-- 数据中心

local mis_ssdbDcClient = require('modules.commhm.dc.ssdbDcClient')
local mis_uu = require('modules.commhm.utils')
local mis_timer = require('modules.commhm.ngxTimerWrap')
local mis_configMgr = require('modules.center_server.luaConfigProxy')
local mis_ABTestSDK = require('modules.commhm.CABTestSDK')
local mis_rank      = require('mis_rank')
local mis_frashsale = require('mis_frashsale')
local uu = mis_uu
local log       	= require("modules.commhm.log");
local auth_check  	= require("modules.business_common.business_auth")
local ngx = ngx
local pairs = pairs
local type = type
local tonumber = tonumber
local table = table
local string = string
local debug = debug
local next = next
local table_insert = table.insert
local math_floor = math.floor
local math_random = math.random
local math_max = math.max
local os_time = os.time
local string_match = string.match
local string_gsub = string.gsub
local string_sub = string.sub

local t_cache = ngx.shared.misCache
local t_timeCache = ngx.shared.misTime

local mis_config = nil
local mis_log = nil
local mis_common = nil
local mis_calcu = nil
local mis_user = nil
local mis_lock = nil
local mis_qps = nil
local mis_bridge = nil
local t_retCode = nil
local mis_network = nil

--------------------------------------------------------------
local mis_data = {
	s_name = string.match(debug.getinfo(1).short_src, '.*/(.*).lua');	-- 模块名称
	t_ABTestSDK = mis_ABTestSDK;
	t_nationalday = {													-- 国庆活动
		t_conf = nil;
		n_status = nil;
	};
	t_twoback = {														-- 二期回流数据
		t_conf_long = nil;
		t_conf_short= nil;
		n_status = nil;
	};
	t_gift = {															-- 礼包数据
		t_conf = nil;
		t_conditionConf = nil;
		n_status = nil;
		t_beitem2gift = nil;
	};
	t_back = {															-- 回流数据
		t_conf = nil;
		n_status = nil;
	};
	t_baoku = {															-- 宝库数据
		t_conf = nil;
		n_status = nil;
	};
	t_coop = {															-- 协作数据
		t_conf = nil;
		n_status = nil;
	};
	t_mission = {														-- 任务数据
		t_conf = nil;
		t_eventConf = nil;
		n_status = nil;
		s_md5 = nil;
	};
	t_birthday = {														-- 生日数据
		t_conf = nil;
		n_status = nil;
	};
	t_rotate = {														-- 转盘数据
		t_conf = nil;
		n_status = nil;
	};
	t_share = {															-- 分享码拉新活动数据
		t_conf = nil;
		n_status = nil;
		s_conf_json=nil;												--配置的json格式，给h5
	};
	t_diversion = {														-- 导流数据
		t_conf = nil;
		n_status = nil;
	};
	t_growthguard = {													-- 成长守护数据
		t_conf = nil;
		n_status = nil;
	};
	t_weekend_gift = {												-- 周末好礼配置
		t_conf = nil;
		n_status = nil;
	};
	t_weekend_gift_v2 = {												-- 周末好礼v2配置
		t_conf = nil;
		n_status = nil;
	};
	t_relic_imitate = {												-- 国宝复刻配置
		t_conf = nil;
		n_status = nil;
	};
	t_concert = {													-- 音乐嘉年华
		t_conf = nil;
		n_status = nil;
	};
	t_doubledan = {													-- 音乐嘉年华
		t_conf = nil;
		n_status = nil;
	};
	t_daily_sign = {												-- 每日签到
		t_conf = nil;
		n_status = nil;
	};
	t_novice_task = {												-- 新手任务（新版）
		t_conf = nil;
		n_status = nil;
	};
	t_awakening_activity = {										-- 觉醒活动
		t_conf = nil;
		n_status = nil;
	};
	t_awakening_tickets = {
		t_conf = nil;
		n_status = nil;
	};
	t_share_mission = {												-- 任务共享模块
		['contest_map'] = {											-- 地图作者评选
			t_conf = nil;
			n_status = nil;
		};
		['contest_video'] = {										-- 视频作者评选
			t_conf = nil;
			n_status = nil;
		};
		['contest_social'] = {										-- 社区作者评选
			t_conf = nil;
			n_status = nil;
		};
		['tang_year'] = {											-- 迎唐年
			t_conf = nil;
			n_status = nil;
		};
		['year_beast'] = {										    -- 战年兽
			t_conf = nil;
			n_status = nil;
		};
		['wealth_god'] = {										    -- 迎财神
			t_conf = nil;
			n_status = nil;
		};
		['share_activity'] = {										-- 分享活动
			t_conf = nil;
			n_status = nil;
		};
		['flower_xiaolou'] = {										-- 花小楼数字专辑
			t_conf = nil;
			n_status = nil;
		};
		['snow_party'] = {											-- 冬雪派对
			t_conf = nil;
			n_status = nil;
		};
		['mini_party'] = {											-- 迷你派对
			t_conf = nil;
			n_status = nil;
		};
		['build_greatwall'] = {										-- 共筑长城
			t_conf = nil;
			n_status = nil;
		};
		['create_convoy'] = {										-- 组建护卫队
			t_conf = nil;
			n_status = nil;
		};
		['void_invade'] = {											-- 虚空来袭
			t_conf = nil;
			n_status = nil;
		};
		['anniversary_roll'] = {									-- 周年庆宝箱
			t_conf = nil;
			n_status = nil;
		};
		['awakening_homepage'] = {									-- 觉醒首页
			t_conf = nil;
			n_status = nil;
		};
		['awakening_books'] = {										-- 觉醒秘籍
			t_conf = nil;
			n_status = nil;
		};
		['awakening_movie'] = {										-- 觉醒电影
			t_conf = nil;
			n_status = nil;
		};
		['mini_worker_mission'] = {									-- 迷你打工人任务
			t_conf = nil;
			n_status = nil;
		};
		['mini_worker_store'] = {									-- 迷你打工人商城
			t_conf = nil;
			n_status = nil;
		};
		['boat_festival'] = {										-- 端午节活动
			t_conf = nil;
			n_status = nil;
		};
		['boat_festival_store'] = {									-- 端午节活动
			t_conf = nil;
			n_status = nil;
		};
		['vip_theme'] = {									        -- 会员主题
			t_conf = nil;
			n_status = nil;
		};
		['map_share'] = {											-- 联机地图分享
			t_conf = nil;
			n_status = nil;
		};
		['map_code'] = {											-- 地图口令分享
			t_conf = nil;
			n_status = nil;
		};
	};
	--三丽鸥数据
	t_sanrio = {														
		t_conf = nil;
		n_status = nil;
	};
	--三丽鸥中秋节数据
	t_moon = {														
		t_conf = nil;
		n_status = nil;
	};
	--皮肤物品表
	t_item_use_skin_def_config = {
		t_conf = nil,
		n_status = nil,
	};
	--三丽鸥国庆
	t_currency = {														
		t_national_conf = nil;
		n_national_status = nil;
		--
		t_currency_conf = nil;
		n_currency_status = nil;
	};
}
local this = mis_data
local n_m_confVer = nil 	-- 配置版本号
local t_m_ssdb = nil 		-- ssdb
local t_m_sysUser = {} 		-- 系统用户
local b_m_giftTimer = nil

-- ngx.ctx.t_params 		-- 请求参数表
-- ngx.ctx.t_users			-- 用户列表
-- ngx.ctx.t_http			-- http对象缓存
-- ngx.ctx.n_logLevel		-- 日志级别

--------------------------------------------------------------
-- 说明：参数存在性校验
-- 参数：t_src			校验模板
--		t_des 			校验数据
-- 		s_parant		外层节点名
-- 返回：n				状态码
--		s 				描述
local function check_params_base(t_src, t_des, s_parant)
	for sn_1, ts_1 in pairs(t_src) do
		if type(sn_1) == 'number' then
			if type(ts_1) == 'table' then
				local n_count = 0
				for _, t_2 in pairs(t_des) do
					n_count = n_count + 1
					for _, s_3 in pairs(ts_1) do
						if not t_2[s_3] then
							local s_desc = 'missing param: ' .. s_3
							mis_log.error(s_desc)
							return t_retCode.n_PARAM_ERR, s_desc
						end
					end
				end
				if n_count == 0 then
					local s_desc = 'empty table: ' .. (s_parant or '')
					mis_log.error(s_desc)
					return t_retCode.n_PARAM_ERR, s_desc
				end
			else
				if not t_des[ts_1] then
					local s_desc =  'missing param: ' .. ts_1
					mis_log.error(s_desc)
					return t_retCode.n_PARAM_ERR, s_desc
				end
			end
		else
			if not t_des[sn_1] then
				local s_desc =  'missing param: ' .. sn_1
				mis_log.error(s_desc)
				return t_retCode.n_PARAM_ERR, s_desc
			end
			local n_code, s_desc = check_params_base(t_src[sn_1], t_des[sn_1], sn_1)
			if n_code ~= t_retCode.n_OK then
				return n_code, s_desc
			end
		end
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：类型纠正
-- 参数：t_src			模板
--		t_des 			数据
local function type_correct_base(t_src, t_des)
	for sn_1, ts_1 in pairs(t_src) do
		if type(sn_1) == 'number' then
			if type(ts_1) == 'table' then
				for _, t_2 in pairs(t_des) do
					for _, s_3 in pairs(ts_1) do
						if t_2[s_3] then
							t_2[s_3] = tonumber(t_2[s_3])
						end
					end
				end
			else
				if t_des[ts_1] then
					t_des[ts_1] = tonumber(t_des[ts_1])
				end
			end
		else
			type_correct_base(t_src[sn_1], t_des[sn_1])
		end
	end
end

--------------------------------------------------------------
-- 说明：长度限定
-- 参数：t_src			模板
--		t_des 			数据
local function length_limit_base(t_src, t_des)
	for sn_1, ts_1 in pairs(t_src) do
		if type(sn_1) == 'string' then
			if type(ts_1) == 'number' then
				if t_des[sn_1] then t_des[sn_1] = string_sub(t_des[sn_1], 1, ts_1) end
			else
				length_limit_base(t_src[sn_1], t_des[sn_1])
			end
		else
			for _, ts_2 in pairs(t_des) do
				for sn_3, n_3 in pairs(ts_1) do
					if ts_2[sn_3] then ts_2[sn_3] = string_sub(ts_2[sn_3], 1, n_3) end
				end
			end
		end
	end
end

--------------------------------------------------------------
-- 说明：数据库定时清理过期数据
local function auto_clean_DB(premature)
	local s_key, s_val
	local n_now = ngx.time()
	local n_select = (t_cache:get('n_misAutoCleanDBSelect') or 0) % #mis_config.t_ssdbDc.t_select
	local s_hash = t_cache:get('s_misAutoCleanDBHash') or ''
	-- 根据当前qps在配置范围内浮动
	local n_num = math_floor(math_max(0, (1-mis_qps.watch('dc')/mis_config.n_autoCleanDBDCLimit))*mis_config.n_autoCleanDBNum)
	mis_log.day('autoCleanDB', 'try|' .. n_select .. '|' .. s_hash .. '|' .. n_num)
	if n_num == 0 then return end
	local ts_ret = t_m_ssdb:hlist(n_select, s_hash, '', n_num)
	ts_ret = mis_common.string_to_table(ts_ret)
	if #ts_ret == 1 and ts_ret[1] == 'ok' then
		t_cache:delete('s_misAutoCleanDBHash')
		t_cache:incr('n_misAutoCleanDBSelect', 1, 0)
	else
		for _, n_uin in pairs(ts_ret) do
			local ts_ = mis_common.string_to_table(t_m_ssdb:hgetall(n_select, n_uin))
			-- hgetall可能异常返回''
			if type(ts_) == 'table' then
				-- 数据格式为数组类型table={key,value,key,value}, 所以遍历步进数为2
				for n_i = 1, #ts_, 2 do
					s_key = ts_[n_i]
					s_val = ts_[n_i+1]
					-- 防止数据数量不为偶数
					if s_key and s_val then
						local s_time = string_match(s_val, '%["_t_"%]=(%d+)')
						if s_time and tonumber(s_time) + mis_config.n_autoCleanDBTime < n_now and mis_config.t_clean_DB[s_key] then
							t_m_ssdb:del(n_select, n_uin, s_key)
							mis_log.day('autoCleanDB', 'del|' .. n_select .. '|' .. n_uin .. '|' .. s_key .. '|' .. s_time)
						end
					end
				end
			end
		end
		t_cache:set('s_misAutoCleanDBHash', ts_ret[#ts_ret])
	end
end
--------------------------------------------------------------
-- 说明：循环触发战年兽事件
local function year_beast_event_loop(b_init)
	local s_type			= mis_config.t_workType.s_YEAR_BEAST
	local t_cache 			= ngx.shared.misSysUser
	local t_sysUser 		= mis_data.get_user(1)
	local n_nowTime			= ngx.time()

	local n_yearBeastNum, s_user, st_desc
	local t_userList, t_uinList, t_lock
	local n_code, s_desc, t_userData

	local s_gobal_key  	= mis_config.t_year_beast.s_gobal_key
	local s_gobal_lock  = mis_config.t_year_beast.s_gobal_lock
	local s_event_key  	= mis_config.t_year_beast.s_event_key
	local s_event_lock 	= mis_config.t_year_beast.s_event_lock

	repeat
		if not t_cache then break end

		n_code, t_userData = t_sysUser:get_share_mission_data(s_type, false, true)
		if n_code ~= t_retCode.n_OK then
			mis_log.day("year_beast_error","year_beast_event_loop error|" .. s_type)
			break
		end

		-------------- 全服次数统计 --------------
		n_code, t_lock = mis_lock.lock(s_gobal_lock)
		if n_code ~= t_retCode.n_OK then
			mis_log.day("year_beast_error","year_beast_event_loop gobal_lock error|" .. s_type .. '|' .. n_code)
			return n_code, 'year_beast_event_loop lock error'
		end

		n_yearBeastNum = t_cache:get(s_gobal_key)
		if not n_yearBeastNum then
			n_yearBeastNum = 0
		else
			t_cache:set(s_gobal_key, 0)
		end

		mis_lock.unlock(t_lock)

		-------------- 全服次数统计 --------------
		t_userData.ctime		  = t_userData.ctime or 0
		t_userData.n_yearBeastNum = t_userData.n_yearBeastNum or 0
		t_userData.n_yearBeastNum = t_userData.n_yearBeastNum + n_yearBeastNum
		t_userData.ctime		  = n_nowTime

		n_code, s_desc   = t_sysUser:set_share_mission_data(s_type, t_userData)
		if n_code ~= t_retCode.n_OK then
			mis_log.day("year_beast_error","year_beast_event_loop set user data error|" .. s_type .. '|' .. n_code)
			break
		end

		local n_code, t_lock = mis_lock.lock(s_event_lock)
		if n_code ~= t_retCode.n_OK then
			mis_log.day("year_beast_error","year_beast_event_loop lock error|" .. s_type .. '|' .. n_code)
			break
		end

		s_user 			= t_cache:get(s_event_key)

		if s_user then
			t_userList = table.loadstring(s_user)
			if t_userList and mis_uu.tableNotEmpty(t_userList) then
				for k, v in pairs(t_userList) do
					t_uinList 		= v
					t_userList[k] 	= nil
					break
				end

				n_code, st_desc = t_cache:set(s_event_key , table.tostring(t_userList))
				if not n_code then
					mis_log.day("year_beast_error","set cache error|" .. s_type .. st_desc)
					mis_lock.unlock(t_lock)
					break
				end
			end
		end

		mis_lock.unlock(t_lock)

		if t_uinList and #t_uinList > 0 then
			for i = 1, #t_uinList do
				local n_userId = tonumber(t_uinList[i] or 0)
				if n_userId > 1000 then

					n_code, st_desc = mis_bridge.notify_mission_event('share_mission_event', n_userId, s_type)
					if n_code ~= t_retCode.n_OK then
						mis_log.day("year_beast_error","notify_mission_event failed!|" .. n_userId .. '|' .. (st_desc or 'nil'))
					end
				end
			end
			mis_log.day("year_beast", "notify_mission_event|" .. mis_common.table_to_json(t_uinList))
		end
	until true

	mis_timer:new():ngx_timer_at(3, year_beast_event_loop)
end

--------------------------------------------------------------
-- 说明：系统礼包数据刷新
local function system_gift_update(premature)
	local n_, n_1, n_code
	local t_2, t_lock, t_sysGift, t_sysGift2
	local n_now = ngx.time()
	local b_update = false
	local t_sysUser = this.get_user(0)
	local t_giftStatus = mis_config.t_giftStatus

	n_code, t_lock = mis_lock.lock('gift_update')
	if n_code ~= t_retCode.n_OK then
		return
	end

	n_code, t_sysGift, t_sysGift2 = t_sysUser:get_gift_data(nil, true)
	if n_code ~= t_retCode.n_OK then
		return
	end

	for n_giftId, t_ in pairs(t_sysGift) do
		if(type(t_) == 'table') then
			t_2 = this.t_gift.t_conf[n_giftId]
			if n_now < t_2.BeginTime then
				-- 礼包未上架
				if t_.status ~= t_giftStatus.n_PRE then
					t_.status = t_giftStatus.n_PRE
					b_update = true
				end
			elseif n_now < t_2.EndTime then
				-- 礼包上架
				if t_.status ~= t_giftStatus.n_ON then
					t_.status = t_giftStatus.n_ON
					b_update = true
				end
				-- 处理限购刷新礼包
				if t_.nextTime and n_now >= t_.nextTime then
				-- 礼包刷新
					n_ = t_.nextTime - t_.freshTime
					n_1 = (n_now - t_.freshTime) % n_
					t_.freshTime = n_now - n_1
					t_.nextTime = n_now + n_ - n_1
					b_update = true
				end
			else
				-- 礼包下架
				if t_.status ~= t_giftStatus.n_OFF then
					t_.status = t_giftStatus.n_OFF
					b_update = true
				end
			end
		end
	end
	if b_update then
		t_sysUser:set_gift_data(t_sysGift, t_sysGift2)
	end
	t_m_ssdb:final()
	mis_lock.unlock(t_lock)
end

--------------------------------------------------------------
-- 说明：模块包含
-- 参数：模块表
this.modules_include = function(t_modules)
	mis_config = t_modules.mis_config
	mis_log = t_modules.mis_log
	mis_common = t_modules.mis_common
	mis_calcu = t_modules.mis_calcu
	mis_user = t_modules.mis_user
	mis_lock = t_modules.mis_lock
	mis_qps = t_modules.mis_qps
	mis_bridge = t_modules.mis_bridge
	t_retCode = mis_config.t_retCode
	mis_network = t_modules.mis_network
end

--------------------------------------------------------------
-- 说明：紧急通道
this.emergency = function()
	-- [参数表预处理]
	local t_rawParams = ngx.req.get_uri_args()
	mis_log.set_print_terminal(t_rawParams.log)
	-- 转码、解码
	if t_rawParams.s7 and t_rawParams.s7t then
		local n_code, s_desc = mis_common.data_ntoh(t_rawParams.s7, t_rawParams.s7t)
		if n_code ~= t_retCode.n_OK then
			return n_code, s_desc
		end
		ngx.ctx.t_params = ngx.decode_args(s_desc)
	else
		ngx.ctx.t_params = t_rawParams
	end
	-- 适配第三方库
	ngx.ctx.m_params = ngx.ctx.t_params
	-- 参数补充
	local t_headers = ngx.req.get_headers()
	ngx.ctx.t_params.s_remoteAddr = t_headers["X-Real-IP"] or t_headers["X-Forwarded-For"] or ngx.var.remote_addr or 'null'
	ngx.ctx.xff = ngx.ctx.t_params.s_remoteAddr
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 礼包系统配置
this.handle_gift_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_gift_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_gift_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_gift_conf", "return empty" )
		return
	end

	local b_
	local n_confVer, s_err
	local n_now, sn_code, n_, n_1, n_2, n_3, n_4, n_5, n_6, n_7, n_8 = ngx.time()
	local n_day, n_dayRest = 86400, mis_common.time_to_next_day()
	local n_week, n_weekRest = 604800, mis_common.time_to_next_week()
	local n_month, n_monthRest = mis_common.month_time(), mis_common.time_to_next_month()
	local s_key1, s_key2, s_key3, s_desc
	local t_, t_2, t_3, t_4, t_con, t_tmp, t_tmp2, t_sysGift, t_sysGift2, t_sysUser, t_sysConf, t_beitem2gift, t_first, t_default
	local t_giftStatus = mis_config.t_giftStatus

	t_sysUser = this.get_user(0)
	sn_code, t_sysGift, t_sysGift2 = t_sysUser:get_gift_data()
	if sn_code ~= t_retCode.n_OK then
		mis_log.day('center_server', 'get_sys_gift_data error sn_code:' .. sn_code)
		return sn_code, t_sysGift
	end

	sn_code, t_sysConf = t_sysUser:get_gift_conf()
	if sn_code ~= t_retCode.n_OK then
		mis_log.day('center_server', 'get_sys_gift_conf error sn_code:' .. sn_code)
		return sn_code, t_sysConf
	end

	t_tmp = t_ret.gift
	t_ret = {}
	t_con = {}
	t_beitem2gift = {}
	for _, t_ in pairs(t_tmp) do
		t_ret[t_.ID] = t_
		-- 数据类型纠正
		for s_, _v in pairs(t_) do if _v == '' then t_[s_] = nil end end
		if t_.Limit and t_.Limit == 0 then t_.Limit = nil end
		t_.title = string_gsub(t_.title, '\n', '')
		for n_ = 1, 15 do
			t_['title_' .. n_] = nil
		end

		-- 礼包抽奖相关
		if t_.switch_skin ~= nil then t_.switch_skin = mis_uu.split(t_.switch_skin,',') end
		if t_.switch_id ~= nil then t_.switch_id = mis_uu.split(t_.switch_id,',') end
		if t_.switch_id_num ~= nil then t_.switch_id_num = mis_uu.split(t_.switch_id_num,',') end
		if t_.probability ~= nil then t_.probability = mis_uu.split(t_.probability,',') end
		if t_.switch_tag ~= nil then t_.switch_tag = mis_uu.split(t_.switch_tag,',') end
		if t_.Beitem ~= nil then t_beitem2gift[t_.Beitem] = t_.ID end

		t_2 = t_sysGift[t_.ID]
		if not t_2 then
			-- 创建系统礼包
			t_2 = {}
			t_sysGift[t_.ID] = t_2
		end

		-- 刷新系统礼包状态
		if n_now < t_.BeginTime then
			t_2.status = t_giftStatus.n_PRE
		elseif n_now < t_.EndTime then
			t_2.status = t_giftStatus.n_ON
		else
			t_2.status = t_giftStatus.n_OFF
		end

		-- 限购刷新礼包
		if t_.Limit and t_.RefreshType and t_.RefreshType ~= 0 then
			t_.b_refresh = 1
			if t_.RefreshType == 1 then
				n_ = n_dayRest
				n_2 = n_day
			elseif t_.RefreshType == 2 then
				n_ = n_weekRest
				n_2 = n_month
			elseif t_.RefreshType == 3 then
				n_ = n_monthRest
				n_2 = n_month
			elseif t_.RefreshType == 4 and t_.Refreshtime and t_.Refreshtime > 0 then
				n_ = t_.Refreshtime - (n_now - t_.BeginTime) % t_.Refreshtime
				n_2 = t_.Refreshtime
			else
				n_ = nil
			end
			if n_ then
				if not t_2.nextTime or t_2.nextTime ~= n_now + n_ then
					t_2.freshTime = n_now + n_ - n_2
					t_2.nextTime = n_now + n_
				end
			else
				t_2.freshTime = nil
				t_2.nextTime = nil
			end
		else
			t_2.freshTime = nil
			t_2.nextTime = nil
		end
		t_.t_content = {giftId = t_.ID, t_data = {}}
		t_.t_contentMaidian = {}
		t_.t_price = {}
		t_.Discount = t_.Discount or 1
		t_.t_contentId = {}
		for i = 1, 100 do
			s_key1 = 'Content' .. i
			s_key2 = 'Num' .. i
			s_key3 = 'Ori' .. i
			if not t_[s_key1] then break end
			t_.t_price[t_[s_key1]] = t_[s_key3]
			if t_.CostType == mis_config.t_costType.n_COIN then
				t_.t_content.t_data[t_[s_key1]] = {id = t_[s_key1], num = t_[s_key2]}
				t_.t_contentMaidian[t_[s_key1]] = {id = t_[s_key1], num = t_[s_key2], price = t_[s_key3]}
			else
				table.insert(t_.t_content.t_data, {id = t_[s_key1], num = t_[s_key2]})
				table.insert(t_.t_contentMaidian, {id = t_[s_key1], num = t_[s_key2], price = t_[s_key3]})
			end
			table.insert(t_.t_contentId, t_[s_key1])
			t_[s_key1] = nil
			t_[s_key2] = nil
			t_[s_key3] = nil
		end
		t_.t_condition = {}
		if t_.Condition1 then
			t_.Condition1 = tostring(t_.Condition1)
			local t_value = {}
			for s_ in t_.Condition1:gmatch('%d+') do
				t_value[s_] = 1
			end
			table.insert(t_.t_condition, {s_key = 'apiid', t_value = t_value})
			t_.Condition1 = nil
		end
		if t_.Condition2 then
			local t_value = {}
			local s_l, s_r = t_.Condition2:match('%[(.*)-(.*)%]')
			t_value.n_l, t_value.n_r = mis_common.version_to_number(s_l), mis_common.version_to_number(s_r)
			table.insert(t_.t_condition, {s_key = 'ver', t_value = t_value})
			t_.Condition2 = nil
		end
		if t_.Condition3 then
			local t_value = {}
			for s_ in t_.Condition3:gmatch('%d+') do
				t_value[s_] = 1
			end
			table.insert(t_.t_condition, {s_key = 'lang', t_value = t_value})
			t_.Condition3 = nil
		end
		if t_.Condition4 then
			local t_value = {}
			for s_ in t_.Condition4:gmatch('%a+') do
				t_value[s_] = 1
			end
			table.insert(t_.t_condition, {s_key = 'country', t_value = t_value})
			t_.Condition4 = nil
		end
		if t_.Condition5 then
			local t_value = {}
			t_value.n_l, t_value.n_r = t_.Condition5:match('%[(.*)-(.*)%]')
			t_value.n_l = tonumber(t_value.n_l)
			t_value.n_r = tonumber(t_value.n_r)
			table.insert(t_.t_condition, {s_key = 'lostday', t_value = t_value})
			t_.Condition5 = nil
		end
		if t_.Condition6 then
			local t_value = {}
			t_value.n_l, t_value.n_r = t_.Condition6:match('%[(.*)-(.*)%]')
			t_value.n_l = tonumber(t_value.n_l)
			t_value.n_r = tonumber(t_value.n_r)
			table.insert(t_.t_condition, {s_key = 'registerday', t_value = t_value})
			t_.Condition6 = nil
		end
		if t_.Condition7 then
			local t_value = {}
			t_value.n_l, t_value.n_r = t_.Condition7:match('%[(.*)-(.*)%]')
			t_value.n_l = tonumber(t_value.n_l)
			t_value.n_r = tonumber(t_value.n_r)
			table.insert(t_.t_condition, {s_key = 'pay', t_value = t_value})
			t_.Condition7 = nil
		end
		if #t_.t_condition > 0 then
			t_con[t_.ID] = t_
		end
	end

	-- 过期数据清理
	for n_giftId, t_ in pairs(t_sysGift) do
		if(type(t_) == 'table') then
			if not t_ret[n_giftId] then
				t_sysGift[n_giftId] = nil
			end
		end
	end

	-- set back
	sn_code, s_desc = t_sysUser:set_gift_data(t_sysGift, t_sysGift2)
	if sn_code ~= t_retCode.n_OK then
		mis_log.day('center_server', 'set_sys_gift_data error sn_code:' .. sn_code)
		return sn_code, s_desc
	end
	sn_code, s_desc = t_sysUser:set_gift_conf(t_ret)
	if sn_code ~= t_retCode.n_OK then
		mis_log.day('center_server', 'set_sys_gift_conf error sn_code:' .. sn_code)
		return sn_code, s_desc
	end

	-- 上架/更新/下架日志
	for n_giftId, t_ in pairs(t_ret) do
		if not t_sysConf[n_giftId] then
			-- 上架
			t_2 = {}
			for _, t_3 in pairs(t_.t_contentMaidian) do table.insert(t_2, t_3) end
			mis_log.remote_day('gift', 'ok_on|' .. n_giftId .. '|' .. t_.title .. '|' .. mis_common.table_to_json(t_2) .. '|' ..
					(t_.RefreshType or 'nil') .. '|' .. t_.tag .. '|' .. t_.CostType .. '|' .. t_.Cost)
		elseif not mis_common.table_compare(t_, t_sysConf[n_giftId]) then
			-- 更新
			t_2 = {}
			for _, t_3 in pairs(t_.t_contentMaidian) do table.insert(t_2, t_3) end
			mis_log.remote_day('gift', 'ok_update|' .. n_giftId .. '|' .. t_.title .. '|' .. mis_common.table_to_json(t_2) .. '|' ..
					(t_.RefreshType or 'nil') .. '|' .. t_.tag .. '|' .. t_.CostType .. '|' .. t_.Cost)
		end
		t_sysConf[n_giftId] = nil
	end
	for n_giftId, t_ in pairs(t_sysConf) do
		-- 下架
		t_2 = {}
		for _, t_3 in pairs(t_.t_contentMaidian) do table.insert(t_2, t_3) end
		mis_log.remote_day('gift', 'ok_off|' .. n_giftId .. '|' .. t_.title .. '|' .. mis_common.table_to_json(t_2) .. '|' ..
				(t_.RefreshType or 'nil') .. '|' .. t_.tag .. '|' .. t_.CostType .. '|' .. t_.Cost)
	end

	if not b_m_giftTimer then
		s_desc, s_err = mis_timer:new():ngx_timer_every(mis_config.n_sysGiftUpdateInterval, system_gift_update)
		if s_err then
			s_err = 'start ngx.timer.every failed, ' .. s_err
			mis_log.error(s_err)
			return t_retCode.n_SYS_ERR, s_err
		end
		b_m_giftTimer = true
	end

	this.t_gift.t_conf = t_ret
	this.t_gift.t_conditionConf = t_con
	this.t_gift.n_status = mis_config.t_workStatus.n_ENABLE
	this.t_gift.t_beitem2gift = t_beitem2gift
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 回归系统配置
this.handle_back_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_back_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_back_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_back_conf", "return empty" )
		return
	end

	local t_tmp = t_ret[1]
	t_ret = {}
	t_ret.n_lostTime = t_tmp.lost_day * 86400
	t_ret.n_missionTime = t_tmp.mission_day * 86400
	t_ret.n_showTime = t_tmp.show_day * 86400
	t_ret.t_mail = {}
	for _, t_ in pairs(t_tmp.mail) do
		table.insert(t_ret.t_mail, {id = t_.itemId, num = t_.num})
	end
	t_ret.t_progress = {}
	for n_, t_ in pairs(t_tmp.progress) do
		local t_option = nil
		if t_.option then
			t_option = {}
			for _, t_2 in pairs(t_.option) do
				t_option[t_2.itemId] = {
					n_itemId = t_2.itemId;
					n_num = t_2.num;
				}
			end
		end
		t_ret.t_progress[n_] = {
			n_itemId = t_.itemId;
			n_num = t_.num;
			n_price = t_.price;
			t_option = t_option;
		}
	end
	t_ret.t_bonus = {}
	for n_, t_ in pairs(t_tmp.bonus) do
		t_ret.t_bonus[n_] = {
			n_itemId = t_.itemId;
			n_num = t_.num;
			n_price = t_.price;
			n_limit = t_.limit;
		}
	end
	t_ret.t_mission = {}
	for n_, t_ in pairs(t_tmp.mission) do
		if t_.step_type then
			t_ret.t_mission[n_] = {
				b_heir = t_.heir == 1 and true or false;
				n_top = t_.heir == 1 and t_[#t_].target or nil;
				n_event = t_.event;
				n_stepType = t_.step_type;
			}
			for n_2 = 1, #t_ do
				t_ret.t_mission[n_][n_2] = {
					n_target = t_[n_2].target;
					n_score = t_[n_2].score;
				}
			end
		else
			t_ret.t_mission[n_] = {
				n_target = t_[1].target or 1;
				n_event = t_[1].event;
				n_score = t_[1].score;
				b_recycle = t_[1].recycle == 1 and true or false;
			}
		end
	end
	this.t_back.t_conf = t_ret
	this.t_back.n_status = mis_config.t_workStatus.n_ENABLE
end

--------------------------------------------------------------
-- 迷你宝库配置
this.handle_baoku_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_baoku_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_baoku_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_baoku_conf", "return empty" )
		return
	end

	local t_tmp = t_ret.baoku
	t_ret = {baoku = {}, coin = {}}
	for _, t_ in pairs(t_tmp) do
		t_ret.baoku[t_.id] = {
			n_startTime = mis_common.date_to_unix(t_.start_time);
			n_endTime = mis_common.date_to_unix(t_.end_time);
			n_closeTime = mis_common.date_to_unix(t_.close_time);
			n_coinId = t_.coin;
			t_goods = {};
		}
		-- 货币到宝库的反向映射
		if not t_ret.coin[t_.coin] then
			t_ret.coin[t_.coin] = t_.id
		else
			-- 如果有多个宝库，只会映射到最新的那个
			if t_ret.baoku[t_ret.coin[t_.coin]].n_startTime < t_ret.baoku[t_.id].n_startTime then
				t_ret.coin[t_.coin] = t_.id
			end
		end
		for n_, t_2 in pairs(t_.goods) do
			t_ret.baoku[t_.id].t_goods[n_] = {
				n_price = t_2.price;
				n_limit = t_2.limit;
				b_focus = t_2.focus and true or false;
				n_itemId = t_2.itemId;
				n_num = t_2.num;
			}
		end
	end
	this.t_baoku.t_conf = t_ret
	this.t_baoku.n_status = mis_config.t_workStatus.n_ENABLE

	-- 更新周末好礼配置
	this.handle_weekend_gift_conf(t_content)

	-- 更新每日签到配置
	this.handle_daily_sign_conf(t_content)
	
	-- 更新周末好礼v2配置
	this.handle_weekend_gift_v2_conf(t_content)
end

--------------------------------------------------------------
-- 周末好礼配置
this.handle_weekend_gift_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_weekend_gift_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_weekend_gift_conf", "error_no_content" )
		return
	end

	if  not (type(t_ret) == 'table' and type(t_ret.weekend_gift) == 'table') then
		mis_log.day( "center_server", "handle_weekend_gift_conf", "return empty" )
		return
	end

	local t_tmp = t_ret.weekend_gift
	local t_rotate_start = uu.split(t_tmp.rotate_start, ":")
	local t_rotate_end = uu.split(t_tmp.rotate_end, ":")
	local t_mail_send_time = uu.split(t_tmp.mail.send_time, ":")
	local t_mail = {}

	t_mail.n_send = tonumber(t_tmp.mail.send)
	t_mail.n_send_weekday = tonumber(t_tmp.mail.send_weekday)
	t_mail.t_send_time = {hour = tonumber(t_mail_send_time[1]), min = tonumber(t_mail_send_time[2])}
	t_mail.s_title = t_tmp.mail.title
	t_mail.s_content = t_tmp.mail.content
	t_mail.n_jumpTo = tonumber(t_tmp.mail.jump_to)

	t_ret = {
		n_startTime = mis_common.date_to_unix(t_tmp.start_time);
		n_endTime = mis_common.date_to_unix(t_tmp.end_time);

		t_rotate_start = {hour = tonumber(t_rotate_start[1]), min = tonumber(t_rotate_start[2])},
		t_rotate_end = {hour = tonumber(t_rotate_end[1]), min = tonumber(t_rotate_end[2])},

		t_subscribe_award = t_tmp.subscribe_award,
		t_login_award = t_tmp.login_award,
		t_login_award_ratio = t_tmp.login_award_ratio,

		t_mail = t_mail,
	}

	if t_tmp.test_offset_time ~= nil and t_tmp.test_offset_time ~= "" then
		t_ret.n_test_offset_time = mis_common.date_to_unix(t_tmp.test_offset_time);
	end

	this.t_weekend_gift.t_conf = t_ret
	this.t_weekend_gift.n_status = mis_config.t_workStatus.n_ENABLE
end

--------------------------------------------------------------
-- 周末好礼配置
this.handle_weekend_gift_v2_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_weekend_gift_conf_v2|using_content-1|" .. #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_weekend_gift_conf_v2|error_no_content" )
		return
	end

	if  not (type(t_ret) == 'table' and type(t_ret.weekend_gift_v2) == 'table') then
		mis_log.day( "center_server", "handle_weekend_gift_conf_v2|return empty" )
		return
	end

	local t_tmp = t_ret.weekend_gift_v2
	local t_rotate_start = uu.split(t_tmp.rotate_start, ":")
	local t_rotate_end = uu.split(t_tmp.rotate_end, ":")
	local t_push_time = uu.split(t_tmp.push.send_time, ":")
	local t_push = {}
	local t_subscribe_award = {}

	t_push.n_send = tonumber(t_tmp.push.send)
	t_push.n_send_weekday = tonumber(t_tmp.push.send_weekday)
	t_push.t_send_time = {hour = tonumber(t_push_time[1]), min = tonumber(t_push_time[2])}
	t_push.s_title = t_tmp.push.title
	t_push.s_content = t_tmp.push.content
	t_push.n_prepare_sec = (tonumber(t_tmp.push.prepare_min) or 0) * 60

	if t_tmp.subscribe_award then
		for level, pool in pairs(t_tmp.subscribe_award) do
			local t_roll = {}
			t_roll.n_totalWeight = 0
			t_roll.t_awards = {}
			for _, v in pairs(pool) do
				t_roll.n_totalWeight = t_roll.n_totalWeight + (v.weight or 0)
				table.insert(t_roll.t_awards, {
					s_itemId = v.itemId, n_num = tonumber(v.num), n_weight = tonumber(v.weight)
				})
			end
			t_subscribe_award[level] = t_roll
		end
	end 

	t_ret = {
		n_startTime = mis_common.date_to_unix(t_tmp.start_time);
		n_endTime = mis_common.date_to_unix(t_tmp.end_time);

		t_rotate_start = {hour = tonumber(t_rotate_start[1]), min = tonumber(t_rotate_start[2])},
		t_rotate_end = {hour = tonumber(t_rotate_end[1]), min = tonumber(t_rotate_end[2])},

		t_subscribe_award = t_subscribe_award,

		t_push = t_push,
	}

	if t_tmp.test_offset_time ~= nil and t_tmp.test_offset_time ~= "" then
		t_ret.n_test_offset_time = mis_common.date_to_unix(t_tmp.test_offset_time);
	end

	this.t_weekend_gift_v2.t_conf = t_ret
	this.t_weekend_gift_v2.n_status = mis_config.t_workStatus.n_ENABLE

	mis_log.day( "center_server", "handle_weekend_gift_conf_v2 ok|" .. uu.to_str(this.t_weekend_gift_v2))
end

--------------------------------------------------------------
-- 每日签到配置
this.handle_daily_sign_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_daily_sign_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_daily_sign_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_daily_sign_conf", "return empty" )
		return
	end

	local t_tmp = t_ret.daily_sign

	t_ret = {
		n_startTime = mis_common.date_to_unix(t_tmp.start_time);
		n_endTime = mis_common.date_to_unix(t_tmp.end_time);

		t_adult_sign = t_tmp.adult_sign,
		t_under_age_sign = t_tmp.under_age_sign,
		t_sign_award = t_tmp.sign_award,
		n_notice_control = t_tmp.notice_control,

		s_ABTest = t_tmp.ABTest,
	}

	if t_tmp.test_offset_time ~= nil and t_tmp.test_offset_time ~= "" then
		t_ret.n_test_offset_time = mis_common.date_to_unix(t_tmp.test_offset_time);
	end

	this.t_daily_sign.t_conf = t_ret
	this.t_daily_sign.n_status = mis_config.t_workStatus.n_ENABLE

	mis_log.day("daily_sign", 'daily_sign_conf:' .. mis_common.table_to_string(this.t_daily_sign))
end

--------------------------------------------------------------
-- 国宝复刻配置
this.handle_relic_imitate_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_weekend_gift_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_weekend_gift_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_weekend_gift_conf", "return empty" )
		return
	end

	local t_tmp = t_ret[7]
	local t_map = {}
	for k, v in pairs(t_tmp.vote_map) do
		v.map_id = tonumber(v.map_id)
		t_map[k] = v
	end

	t_ret = {
		n_startTime = mis_common.date_to_unix(t_tmp.startTime);
		n_endTime = mis_common.date_to_unix(t_tmp.endTime);

		t_mission = t_tmp.mission,
		t_vote_map = t_map,
		t_vote_award = t_tmp.vote_award,
	}

	if t_tmp.test_offset_time ~= nil and t_tmp.test_offset_time ~= "" then
		t_ret.n_test_offset_time = mis_common.date_to_unix(t_tmp.test_offset_time);
	end

	this.t_relic_imitate.t_conf   = t_ret
	this.t_relic_imitate.n_status = mis_config.t_workStatus.n_ENABLE
end

--------------------------------------------------------------
-- 音乐嘉年华配置
this.handle_concert_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_concert_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_concert_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_concert_conf", "return empty" )
		return
	end
	if not (mis_uu.tableNotEmpty(t_ret[8]) and t_ret[8].noteStore and t_ret[8].taskList) then
		mis_log.day( "center_server", "handle_concert_conf", "return empty conf" )
		return
	end

	local t_tmp 		= t_ret[8]
	local t_taskList	= {}
	local t_noteStore 	= {}
	local t_goods 		= {}
	local n_now 		= ngx.time()

	for k, v in pairs(t_tmp.noteStore.goods) do
		if v.items and mis_uu.tableNotEmpty(v.items) and v.price then
			local n_k			 = tonumber(k)
			t_goods[n_k]		 = {}
			t_goods[n_k].num 	 = tonumber(v.num)
			t_goods[n_k].price   = tonumber(v.price)
			t_goods[n_k].limit   = tonumber(v.limit)
			t_goods[n_k].t_items = {}

			for k2, v2 in pairs(v.items) do
				table.insert(t_goods[n_k].t_items, {id = v2.id, num = v2.num})
			end
		end
	end

	t_noteStore = {
		n_startTime 	= mis_common.date_to_unix(t_tmp.noteStore.startTime or '1970-01-01');
		n_endTime 		= mis_common.date_to_unix(t_tmp.noteStore.endTime or '1970-01-01');
		s_versionMin 	= t_tmp.noteStore.versionMin or '0';
		t_goods 		= t_goods;
	}

	for k, v in pairs(t_tmp.taskList) do
		local n_taskId 	= tonumber(k)
		local t_mission	= {}
		t_taskList[n_taskId] = {}

		for k2, v2 in pairs(v.mission) do
			local t_tmp 		 = {}
			local n_eventId 	 = tonumber(v2.event)
			t_mission[n_eventId] = t_mission[n_eventId] or {}
			t_tmp.t_bonus		 = {}

			if v2.daily and tonumber(v2.daily) == 1 then
				t_tmp.b_daily = true
			else
				t_tmp.b_daily = false
			end
			if v2.weekly and tonumber(v2.weekly) == 1 then
				t_tmp.b_weekly = true
			else
				t_tmp.b_weekly = false
			end

			for k3, v3 in pairs(v2.bonus) do
				t_tmp.t_bonus[tonumber(k3)] = {
					s_itemId 	= v3.itemId;
					n_num 		= tonumber(v3.num);
				}
			end
			t_tmp.n_subTaskId 	= tonumber(k2)
			t_tmp.n_target 		= v2.target
			t_tmp.n_gain_item 	= v2.gain_item
			table.insert(t_mission[n_eventId], t_tmp)
		end

		if v.auto and tonumber(v.auto) == 1 then
			t_taskList[n_taskId].b_auto = true
		else
			t_taskList[n_taskId].b_auto = false
		end

		t_taskList[n_taskId].n_startTime 	= mis_common.date_to_unix(v.startTime or '1970-01-01')
		t_taskList[n_taskId].n_endTime 		= mis_common.date_to_unix(v.endTime or '1970-01-01')
		t_taskList[n_taskId].s_versionMin 	= v.versionMin or '0'
		t_taskList[n_taskId].t_mission		= t_mission
		
		if not mis_uu.tableNotEmpty(t_mission) then
			t_taskList[n_taskId] = nil
			log.day_list("concert_warn", "this t_mission is empty", n_taskId)
		end
	end

	this.t_concert.t_conf   = {
		n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
		n_endTime 		= mis_common.date_to_unix(t_tmp.endTime or '1970-01-01');
		t_noteStore 	= t_noteStore;
		t_taskList 		= t_taskList;
		t_codePrefix	= t_tmp.codePrefix;
		n_codeExchangeNote = t_tmp.codeExchangeNote;
		t_apiids 		= t_tmp.apiids and mis_uu.split(t_tmp.apiids, ',') or {};
		n_version_min   = mis_common.version_to_number(t_tmp.versionMin or '0.0.0');
	}

	if t_tmp.control and tonumber(t_tmp.control) == 1 then
		this.t_concert.n_status = mis_config.t_workStatus.n_ENABLE
	else
		this.t_concert.n_status = mis_config.t_workStatus.n_DISABLE
	end

	mis_log.day("concert", 'concert_conf:' .. mis_common.table_to_string(this.t_concert))
end

--------------------------------------------------------------
-- 新版新手任务配置
this.handle_novice_task_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_novice_task_conf|using_content-1|" .. #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_novice_task_conf|error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_novice_task_conf|return empty" )
		return
	end

	local t_tmp 		= t_ret[9]
	local t_taskList	= {[1] = {}}
	local t_allTasks	= {[1] = {}}
	local n_now 		= ngx.time()
	local t_push		= {}
	local t_test_uin    = {}

	if not mis_uu.tableNotEmpty(t_tmp) then
		mis_log.day( "center_server", "handle_novice_task_conf|return empty 2" )
		return
	end

	local t_push_time = uu.split(t_tmp.push.send_time, ":")
	t_push.n_send = tonumber(t_tmp.push.send) or 0
	-- T + n发送，配置send_delay以天为单位，读配置后转为秒
	t_push.n_send_delay = math_floor((tonumber(t_tmp.push.send_delay) or 1) * 86400)
	t_push.t_send_time = {hour = tonumber(t_push_time[1]), min = tonumber(t_push_time[2])}
	t_push.n_start_time = mis_common.date_to_unix(t_tmp.push.start_time or '1970-01-01')
	if t_tmp.push.test_uin then
		for i = 1, #t_tmp.push.test_uin do
			t_test_uin[t_tmp.push.test_uin[i]] = 1
		end
	end
	t_push.t_test_uin = t_test_uin

	do
		local n_taskId 	= 1
		local t_mission	= {}
		t_taskList[n_taskId] = {}
		t_allTasks[n_taskId] = {}

		for k2, v2 in pairs(t_tmp.mission) do
			local t_tmp 		 = {}
			local n_eventId 	 = tonumber(v2.event)
			t_mission[n_eventId] = t_mission[n_eventId] or {}
			t_tmp.t_bonus		 = {}

			if v2.daily and tonumber(v2.daily) == 1 then
				t_tmp.b_daily = true
			else
				t_tmp.b_daily = false
			end
			if v2.weekly and tonumber(v2.weekly) == 1 then
				t_tmp.b_weekly = true
			else
				t_tmp.b_weekly = false
			end

			for k3, v3 in pairs(v2.bonus) do
				t_tmp.t_bonus[tonumber(k3)] = {
					s_itemId 	= v3.itemId;
					n_num 		= tonumber(v3.num);
				}
			end
			t_tmp.n_subTaskId 	= tonumber(k2)
			t_tmp.n_target 		= v2.target
			t_tmp.n_gain_item 	= v2.gain_item
			table.insert(t_mission[n_eventId], t_tmp)
		end

		t_taskList[n_taskId].b_auto = true

		t_taskList[n_taskId].n_startTime 	= mis_common.date_to_unix('1970-01-01')
		t_taskList[n_taskId].n_endTime 		= mis_common.date_to_unix('2999-01-01')
		t_taskList[n_taskId].s_versionMin 	= '0'
		t_taskList[n_taskId].t_mission		= t_mission
		t_allTasks[n_taskId]				= t_taskList[n_taskId]

		if n_now > t_taskList[n_taskId].n_endTime then
			t_taskList[n_taskId] = nil
			log.day_list("novice_task_warn", "this activity is expired", n_taskId)
		end
		if not mis_uu.tableNotEmpty(t_mission) then
			t_taskList[n_taskId] = nil
			log.day_list("novice_task_warn", "this t_mission is empty", n_taskId)
		end
	end

	this.t_novice_task.t_conf   = {
		n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
		n_endTime 		= mis_common.date_to_unix(t_tmp.endTime or '1970-01-01');
		t_taskList 		= t_taskList;
		t_allTasks		= t_allTasks;
		n_duration      = t_tmp.duration * 86400;
		n_pending_duration = t_tmp.pending_duration * 86400;
		n_finalAwardTarget = t_tmp.final_award_target;
		t_trySuitAward	= t_tmp.try_suit_award;
		t_finalSuitAward = t_tmp.final_suit_award;
		t_dailySignAward = t_tmp.daily_sign_award;
		t_newUserAward	 = t_tmp.new_user_award;
		t_newEventConf	= t_tmp.new_event_conf;
		s_ABTest 		= t_tmp.ABTest;
		t_apiids 		= t_tmp.apiids and mis_uu.split(t_tmp.apiids, ',') or {};
		n_version_min   = mis_common.version_to_number(t_tmp.versionMin or '0.0.0');
		t_push			= t_push;
	}

	if t_tmp.control and tonumber(t_tmp.control) == 1 then
		this.t_novice_task.n_status = mis_config.t_workStatus.n_ENABLE
	else
		this.t_novice_task.n_status = mis_config.t_workStatus.n_DISABLE
	end

	mis_log.day("novice_task", 'novice_task_conf:' .. mis_common.table_to_string(this.t_novice_task))
end

--------------------------------------------------------------
-- 协作活动配置
this.handle_coop_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_coop_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_coop_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_coop_conf", "return empty" )
		return
	end

	local t_tmp = t_ret
	t_ret = {}
	for _, t_ in pairs(t_tmp) do
		if type(t_) ~="table" then
			return
		end
		t_ret[t_.ID] = {
			n_startTime = mis_common.date_to_unix(t_.start_time);
			n_endTime = mis_common.date_to_unix(t_.end_time);
		}
		t_tmp = t_ret[t_.ID]
		for n_2, t_2 in pairs(t_.bonus) do
			if not t_tmp.t_bonus then t_tmp.t_bonus = {} end
			t_tmp.t_bonus[n_2] = {n_score = t_2.score, t_data = {}}
			for n_3 = 1, #t_2 do
				table.insert(t_tmp.t_bonus[n_2].t_data, {id = t_2[n_3].itemId, num = t_2[n_3].num})
			end
		end
		t_tmp.t_mission = {}
		t_tmp.t_missionEvent = {}
		t_tmp.t_missionAuto = {}
		for n_2, t_2 in pairs(t_.mission) do
			t_tmp.t_mission[n_2] = {
				n_id = n_2;
				n_score = t_2.score;
				n_event = t_2.event;
				n_target = t_2.target;
				b_daily = t_2.daily and true or false;
			}
			if t_2.event == mis_config.t_coopEvent.n_FINISH then
				table.insert(t_tmp.t_missionAuto, t_tmp.t_mission[n_2])
			else
				if not t_tmp.t_missionEvent[t_2.event] then t_tmp.t_missionEvent[t_2.event] = {} end
				table.insert(t_tmp.t_missionEvent[t_2.event], t_tmp.t_mission[n_2])
			end
		end
	end
	this.t_coop.t_conf = t_ret
	this.t_coop.n_status = mis_config.t_workStatus.n_ENABLE
end

-- 公共任务配置读取元类
local ShareConfig = {
	s_workType = nil,				-- 当前配置业务标识
	s_content = nil,				-- 配置源数据
	t_content = nil,				-- 配置反序列化后的数据

	t_config = nil,					-- 配置内容
	n_status = nil,					-- 总开关
}

-- 获取配置
ShareConfig.getConfig = function(self)
	return {t_conf = self.t_config, n_status = self.n_status}
end

-- 加载配置
ShareConfig.load = function(s_content, s_workType)
	s_workType = s_workType or "Undefine"
	if s_content == nil then
		error(s_workType .. ": content is empty")
	end
	local reader = setmetatable({}, {__index = ShareConfig})
	reader.s_workType = s_workType
	reader.s_content = s_content
	reader.t_content = mis_uu.safe_loadstring(s_content, true)
	reader.t_config = {}
	if reader.t_content == nil then
		error(s_workType .. ": content load fail")
	end
	return reader
end

-- 获取子配置
ShareConfig.ensureConfig = function(self, n_labelId, n_taskId)
	if self.t_content == nil then
		error(self.s_workType .. ": content not loaded")
	end
	
	local t_tmp
	local t_content = self.t_content
	if n_taskId then
		if not t_content[n_labelId] then
			error(self.s_workType .. ": lable [" .. uu.to_str(n_labelId) .. "] not exists")
		end
		if type(t_content[n_labelId].taskList) ~= "table" then
			error(self.s_workType .. ": lable [" .. uu.to_str(n_labelId) .. "] taskList not exists or not table type")
		end
		t_tmp = t_content[n_labelId].taskList[n_taskId]
		if not t_tmp then
			error(self.s_workType .. ": lable [" .. uu.to_str(n_labelId) .. "][" .. uu.to_str(n_labelId) .. "] not exists")
		end
	else
		t_tmp = t_content[n_labelId]
		if not t_tmp then
			error(self.s_workType .. ": lable [" .. uu.to_str(n_labelId) .. "] not exists")
		end
	end
	return t_tmp
end

-- 读取控制配置
ShareConfig.readControl = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	
	t_config.t_apiids 	= t_tmp.apiids and mis_uu.split(t_tmp.apiids, ',') or {};
	t_config.t_noapiids 	= t_tmp.t_noapiids and mis_uu.split(t_tmp.t_noapiids, ',') or {};
	t_config.n_version_min = mis_common.version_to_number(t_tmp.versionMin or '0.0.0');

	if t_tmp.control and tonumber(t_tmp.control) == 1 then
		self.n_status = mis_config.t_workStatus.n_ENABLE
	else
		self.n_status = mis_config.t_workStatus.n_DISABLE
	end
	
	t_config.n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
	t_config.n_endTime 	= mis_common.date_to_unix(t_tmp.endTime or '2030-01-01');
	if t_tmp.tabTime and #t_tmp.tabTime > 0 then
		t_config.n_tabTime = {}
		for i=1,#t_tmp.tabTime do
			t_config.n_tabTime[i] = {}
			t_config.n_tabTime[i].n_startTime = mis_common.date_to_unix(t_tmp.tabTime[i].startTime or '1970-01-01');
			t_config.n_tabTime[i].n_endTime 	= mis_common.date_to_unix(t_tmp.tabTime[i].endTime or '1970-01-01');
		end
	end

	mis_log.day("share_mission", self.s_workType .. ' readControl: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取任务配置
ShareConfig.readMission = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_mission = {}

	-- 没有任务配置
	if not mis_uu.tableNotEmpty(t_tmp.mission) then
		error(self.s_workType .. ": mission is empty")
	end

	for k, v in pairs(t_tmp.mission) do
		local t_subTask 	 = {}
		local n_eventId 	 = tonumber(v.event)
		t_mission[n_eventId] = t_mission[n_eventId] or {}
		t_subTask.t_bonus	 = {}

		if v.daily and tonumber(v.daily) == 1 then
			t_subTask.b_daily = true
		else
			t_subTask.b_daily = false
		end
		if v.weekly and tonumber(v.weekly) == 1 then
			t_subTask.b_weekly = true
		else
			t_subTask.b_weekly = false
		end

		for k2, v2 in pairs(v.bonus) do
			t_subTask.t_bonus[tonumber(k2)] = {
				s_itemId 	= v2.itemId;
				n_num 		= tonumber(v2.num);
			}
		end
		t_subTask.n_subTaskId 	= tonumber(k)
		t_subTask.n_target 		= v.target
		t_subTask.n_gainItem 	= v.gain_item
		t_subTask.n_eventId		= n_eventId
		table.insert(t_mission[n_eventId], t_subTask)
	end

	if t_tmp.auto and tonumber(t_tmp.auto) == 1 then
		t_config.b_auto = true
	else
		t_config.b_auto = false
	end
	t_config.t_mission = t_mission
	t_config.n_exchange_type	= tonumber(t_tmp.exchange_type or 0);

	t_config.n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
	t_config.n_endTime 	= mis_common.date_to_unix(t_tmp.endTime or '2030-01-01');
	if t_tmp.tabTime and #t_tmp.tabTime > 0 then
		t_config.n_tabTime = {}
		for i=1,#t_tmp.tabTime do
			t_config.n_tabTime[i] = {}
			t_config.n_tabTime[i].n_startTime = mis_common.date_to_unix(t_tmp.tabTime[i].startTime or '1970-01-01');
			t_config.n_tabTime[i].n_endTime 	= mis_common.date_to_unix(t_tmp.tabTime[i].endTime or '1970-01-01');
		end
	end

	mis_log.day("share_mission", self.s_workType .. ' readMission: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取兑换配置
ShareConfig.readStore = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_goods = {}
	local t_store
	
	-- 没有商城配置
	if not mis_uu.tableNotEmpty(t_tmp.store) then
		error(self.s_workType .. ": store is empty")
	end
	
	-- 没有道具配置
	if not mis_uu.tableNotEmpty(t_tmp.store.goods) then
		error(self.s_workType .. ": goods is empty")
	end

	t_store = {
		n_startTime 	= mis_common.date_to_unix(t_tmp.store.startTime or '1970-01-01');
		n_endTime 		= mis_common.date_to_unix(t_tmp.store.endTime or '2030-01-01');
		s_versionMin 	= t_tmp.store.versionMin or '0';
		t_goods 		= t_goods;
	}

	for k, v in pairs(t_tmp.store.goods) do
		if v.items and mis_uu.tableNotEmpty(v.items) and v.price then
			local n_k			 = tonumber(k)
			t_goods[n_k]		 = {}
			t_goods[n_k].price   = tonumber(v.price)
			t_goods[n_k].limit   = tonumber(v.limit)
			t_goods[n_k].unique  = tonumber(v.unique)
			t_goods[n_k].t_items = {}

			for k2, v2 in pairs(v.items) do
				table.insert(t_goods[n_k].t_items, {id = v2.id, num = v2.num})
			end
		end
	end

	t_config.t_store = t_store
	t_config.n_exchange_type	= tonumber(t_tmp.exchange_type or 0);

	mis_log.day("share_mission", self.s_workType .. ' readStore: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取赠送活动币配置
ShareConfig.readCurrency = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_currency = {}
	
	-- 没有商城配置
	if not mis_uu.tableNotEmpty(t_tmp.currency) then
		error(self.s_workType .. ": currency is empty")
	end

	-- 赠送开关
	t_currency.n_allowAdd = tonumber(t_tmp.currency.allowAdd) or 0

	-- 单次最大添加数量
	if t_tmp.currency.addCurrencyUpperValue then
		t_currency.n_addCurrencyUpperValue = tonumber(t_tmp.currency.addCurrencyUpperValue) or 0
	end
	
	-- 最多奖励次数
	if t_tmp.currency.addCurrencyUpperCount then
		t_currency.n_addCurrencyUpperCount = tonumber(t_tmp.currency.addCurrencyUpperCount) or 0
	end
	
	-- 单人奖励总数量限制
	if t_tmp.currency.addCurrencyTotalValue then
		t_currency.n_addCurrencyTotalValue = tonumber(t_tmp.currency.addCurrencyTotalValue) or 0
	end

	-- 货币类型
	t_currency.n_exchange_type = tonumber(t_tmp.currency.exchange_type or 0)

	t_config.t_currency = t_currency
	
	mis_log.day("share_mission", self.s_workType .. ' readCurrency: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取抽奖配置
ShareConfig.readRoll = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_roll = {}
	
	-- 没有商城配置
	if not mis_uu.tableNotEmpty(t_tmp.shareRoll) then
		error(self.s_workType .. ": share roll is empty")
	end
	
	-- 公共抽奖
	t_roll.n_daily = tonumber(t_tmp.shareRoll.daily) or 0
	t_roll.n_freeCount = tonumber(t_tmp.shareRoll.freeCount) or 0
	t_roll.n_videoCount = tonumber(t_tmp.shareRoll.videoCount) or 0
	t_roll.n_minVideoInterval = tonumber(t_tmp.shareRoll.minVideoInterval) or 2
	
	t_roll.n_exchange_type = tonumber(t_tmp.shareRoll.exchange_type) or 0
	t_roll.n_specialItemId = tonumber(t_tmp.shareRoll.specialItemId) or 0

	-- 视频允许渠道
	t_roll.t_videoApiidAllow = {}
	if t_tmp.shareRoll.videoApiidAllow then
		for k, v in ipairs(t_tmp.shareRoll.videoApiidAllow) do
			t_roll.t_videoApiidAllow[tonumber(v)] = 1
		end
	end

	t_roll.n_totalWeight = 0
	t_roll.t_awards = {}
	for _, v in pairs(t_tmp.shareRoll.awards) do
		t_roll.n_totalWeight = t_roll.n_totalWeight + (v.weight or 0)
		table.insert(t_roll.t_awards, {
			s_itemId = v.itemId, n_num = tonumber(v.num), n_weight = tonumber(v.weight)
		})
	end
	t_config.t_shareRoll = t_roll

	mis_log.day("share_mission", self.s_workType .. ' readRoll: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取分享码配置
ShareConfig.readCode = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_code = {}
	
	-- 没有商城配置
	if not mis_uu.tableNotEmpty(t_tmp.shareCode) then
		error(self.s_workType .. ": share code is empty")
	end
	
	-- 公共分享码
	t_code.t_prefix = t_tmp.shareCode.prefix or {}						-- 分享码前缀
	t_code.n_init = t_tmp.shareCode.init or 38032637					-- 分享码初始值
	t_code.n_max = t_tmp.shareCode.max or 60466175						-- 分享码最大值
	t_code.n_maxExchange = t_tmp.shareCode.maxExchange or 2				-- 分享码最大兑换次数
	t_code.n_expireType = t_tmp.shareCode.expireType or 1				-- 分享码过期方式：1 当天有效，2 按时间倒计时
	t_code.n_expire = t_tmp.shareCode.expire or 60						-- 分享码过期时间（单位：秒）
	t_code.n_maxLength = t_tmp.shareCode.maxLength or 20				-- 分享码最大长度(字节数，用于快速校验，由开发填写，默认是20);
	t_code.s_pattern = t_tmp.shareCode.pattern or "^%W+%d[0-9a-zA-Z]+$"	-- 分享码正则匹配(用于快速校验，由开发填写，默认是：^%W+%d[0-9a-zA-Z]+$)
	t_code.s_format = t_tmp.shareCode.format or "uint36"				-- 分享码格式化（目前支持：uint36 36进制整数）
	
	t_config.t_shareCode = t_code

	mis_log.day("share_mission", self.s_workType .. ' readCode: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取迎财神配置
ShareConfig.readWealthGod = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}

	t_config.block_max = tonumber(t_tmp.block_max or 500);
	t_config.award_pool = tonumber(t_tmp.award_pool or 10000000);
	t_config.mini_coin_prob = tonumber(t_tmp.mini_coin_prob or 15);
	t_config.minicoin_award_pool = t_tmp.minicoin_award_pool
	t_config.red_envelope_award_pool  = t_tmp.red_envelope_award_pool 

	t_config.low_value_user  = t_tmp.low_value_user 
	t_config.low_value_user.time = mis_common.date_to_unix(t_tmp.low_value_user.time or '2022-01-01');
	t_config.low_value_user.day = tonumber(t_tmp.low_value_user.day or 5);
	t_config.assist_man_count = tonumber(t_tmp.assist_man_count or 4)
	t_config.time_pool_list = {}

	for k,v in pairs(t_tmp.time_pool_list) do
		t_config.time_pool_list[k] = {}
		if v.startTime and v.endTime then
			t_config.time_pool_list[k].startTime = mis_common.date_to_unix(v.startTime )
			t_config.time_pool_list[k].endTime = mis_common.date_to_unix(v.endTime )
		end
		if v.show_pool_num then
			t_config.time_pool_list[k].show_pool_num = tonumber(v.show_pool_num) or 0
		end
 		
	end
	
	mis_log.day("share_mission", self.s_workType .. ' readWealthGod: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取任务配置
ShareConfig.readMiniParty = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_mission = {}
	local t_cake = {}
	-- 没有任务配置
	if not mis_uu.tableNotEmpty(t_tmp.mission) then
		error(self.s_workType .. ": mission is empty")
	end

	for k, v in pairs(t_tmp.cake) do
		if v.id and v.num then
			table.insert(t_cake, { id = tonumber(v.id), num = tonumber(v.num) })
		else
			error(self.s_workType .. ": t_cake is error")
		end
	end

	if t_tmp.bonus and t_tmp.bonus.itemId and t_tmp.bonus.num then
		t_config.t_bonus = { itemId = t_tmp.bonus.itemId, num = tonumber(t_tmp.bonus.num) }
	else
		error(self.s_workType .. ": t_bonus is error")
	end

	t_config.t_cake 		= t_cake

	for k, v in pairs(t_tmp.mission) do
		local t_subTask 	 = {}
		local n_eventId 	 = tonumber(v.event)
		t_mission[n_eventId] = t_mission[n_eventId] or {}
		t_subTask.t_bonus	 = {}

		if v.daily and tonumber(v.daily) == 1 then
			t_subTask.b_daily = true
		else
			t_subTask.b_daily = false
		end
		if v.weekly and tonumber(v.weekly) == 1 then
			t_subTask.b_weekly = true
		else
			t_subTask.b_weekly = false
		end

		t_subTask.n_subTaskId 	= tonumber(k)
		t_subTask.n_target 		= v.target
		t_subTask.n_gainItem 	= tonumber(v.gain_item)
		table.insert(t_mission[n_eventId], t_subTask)
	end

	if t_tmp.auto and tonumber(t_tmp.auto) == 1 then
		t_config.b_auto = true
	else
		t_config.b_auto = false
	end
	t_config.t_mission = t_mission
	t_config.n_exchange_type	= tonumber(t_tmp.exchange_type or 0);

	t_config.n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
	t_config.n_endTime 	= mis_common.date_to_unix(t_tmp.endTime or '2030-01-01');
	if t_tmp.tabTime and #t_tmp.tabTime > 0 then
		t_config.n_tabTime = {}
		for i=1,#t_tmp.tabTime do
			t_config.n_tabTime[i] = {}
			t_config.n_tabTime[i].n_startTime = mis_common.date_to_unix(t_tmp.tabTime[i].startTime or '1970-01-01');
			t_config.n_tabTime[i].n_endTime 	= mis_common.date_to_unix(t_tmp.tabTime[i].endTime or '1970-01-01');
		end
	end

	mis_log.day("share_mission", self.s_workType .. ' readMiniParty: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取任务配置
ShareConfig.readlevelMission = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_taskList = t_tmp.taskList or {}
	local t_config = {}

	-- 没有任务配置
	if not mis_uu.tableNotEmpty(t_taskList) then
		error(self.s_workType .. ": mission is empty")
	end

	for level, task in pairs(t_tmp.taskList) do
		local t_mission = {}
		for k, v in pairs(task.mission) do
			local t_subTask 	 = {}
			local n_eventId 	 = tonumber(v.event)
			t_mission[n_eventId] = t_mission[n_eventId] or {}
			t_subTask.t_bonus	 = {}

			if v.daily and tonumber(v.daily) == 1 then
				t_subTask.b_daily = true
			else
				t_subTask.b_daily = false
			end
			if v.weekly and tonumber(v.weekly) == 1 then
				t_subTask.b_weekly = true
			else
				t_subTask.b_weekly = false
			end

			for k2, v2 in pairs(v.bonus) do
				t_subTask.t_bonus[tonumber(k2)] = {
					s_itemId 	= v2.itemId;
					n_num 		= tonumber(v2.num);
				}
			end
			t_subTask.n_subTaskId 	= tonumber(k)
			t_subTask.n_target 		= v.target
			t_subTask.n_gainItem 	= v.gain_item
			table.insert(t_mission[n_eventId], t_subTask)
		end

		t_config.t_taskList = t_config.t_taskList or {}
		t_config.t_taskList[level] = t_mission
	end

	if t_tmp.auto and tonumber(t_tmp.auto) == 1 then
		t_config.b_auto = true
	else
		t_config.b_auto = false
	end

	t_config.n_exchange_type	= tonumber(t_tmp.exchange_type or 0);

	t_config.n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
	t_config.n_endTime 	= mis_common.date_to_unix(t_tmp.endTime or '2030-01-01');
	if t_tmp.tabTime and #t_tmp.tabTime > 0 then
		t_config.n_tabTime = {}
		for i=1,#t_tmp.tabTime do
			t_config.n_tabTime[i] = {}
			t_config.n_tabTime[i].n_startTime = mis_common.date_to_unix(t_tmp.tabTime[i].startTime or '1970-01-01');
			t_config.n_tabTime[i].n_endTime 	= mis_common.date_to_unix(t_tmp.tabTime[i].endTime or '1970-01-01');
		end
	end

	mis_log.day("level_mission", self.s_workType .. ' readMission: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

	-- copy to config
-- 读取升级配置
ShareConfig.readLevel = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	if mis_uu.tableIsEmpty(t_tmp.level or {}) then
		error(self.s_workType .. ": level is empty")
	end

	-- 缺少升级配置
	if mis_uu.tableIsEmpty(t_tmp.level.levelUp or {}) then
		error(self.s_workType .. ": level.levelUp is empty")
	end

	-- 缺少一级配置
	local levelConf = t_tmp.level.levelUp[1]
	if mis_uu.tableIsEmpty(levelConf or {}) then
		error(self.s_workType .. ": level.levelUp level1 is missing")
	end

	local t_config = {
		n_levelMax = tonumber(t_tmp.level.levelMax) or 0,
		t_levelUp  = {}
	}

	local levelUp = {}
	for lv = 1, t_config.n_levelMax do
		levelConf = t_tmp.level.levelUp[lv]
		if levelConf then
			-- 缺少升级消耗配置
			if mis_uu.tableIsEmpty(levelConf.costItem or {}) then
				error(self.s_workType .. ": level.levelUp[" .. lv .. "] is invalid")
			end

			levelUp = { t_costItem = {}, t_awardItem = {}}
			for _, item in pairs(levelConf.costItem) do
				table_insert(levelUp.t_costItem, {id = item.id, num = item.num})
			end

			for _, item in pairs(levelConf.awardItem or {}) do
				table_insert(levelUp.t_awardItem, {id = item.id, num = item.num})
			end
		end

		t_config.t_levelUp[lv] = levelUp
	end

	mis_log.day("share_mission", self.s_workType .. ' readLevel: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

ShareConfig.readRank = function (self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	if mis_uu.tableIsEmpty(t_tmp.rank or {}) then
		error(self.s_workType .. ": rank is empty")
	end

	local t_config = { t_rank = {}}
	for _, rank in pairs(t_tmp.rank) do
		t_config.t_rank[rank.id] = {
			order_by = rank.orderBy == 'ASC' and 1 or 2,
			updates  = rank.updates == 'INC' and 2 or 1,
			show_num = tonumber(rank.showNum) or 100,
			limit_min = rank.limit_min,
			limit_max = rank.limit_max,
			daily = rank.daily or 0,
			profile = rank.profile,
			profile_clean_time = rank.profile_clean_time and mis_common.date_to_unix(rank.profile_clean_time)
		}
	end

	mis_log.day("share_mission", self.s_workType .. ' readRank: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取斗罗大陆配置
ShareConfig.readDouluodalu = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config
	local t_store
	-- 没有绑定手机配置
	if not mis_uu.tableNotEmpty(t_tmp.bind_phone) then
		error(self.s_workType .. ": bind_phone is empty")
	end
	-- login_rewards
	if not mis_uu.tableNotEmpty(t_tmp.login_rewards) then
		error(self.s_workType .. ": login_rewards is empty")
	end
	if not mis_uu.tableNotEmpty(t_tmp.team_rewards) then
		error(self.s_workType .. ": team_rewards is empty")
	end
	if not mis_uu.tableNotEmpty(t_tmp.vip_rewards) then
		error(self.s_workType .. ": vip_rewards is empty")
	end

	t_config = {
		bind_phone = t_tmp.bind_phone,
		login_rewards = t_tmp.login_rewards,
		team_rewards = t_tmp.team_rewards,
		vip_rewards = t_tmp.vip_rewards,
		ready_rewards = t_tmp.ready_rewards,
		badge_level = t_tmp.badge_level,
		stage = t_tmp.stage,
	}

	mis_log.day("share_mission", self.s_workType .. ' readStore: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		if v.startTime then
			v.n_startTime 	= mis_common.date_to_unix(v.startTime or '1970-01-01')
		end
		if v.endTime then
			v.n_endTime = mis_common.date_to_unix(v.endTime or '2030-01-01')
		end
		self.t_config[k] = v
	end
	self.t_config.daily_max_limit = t_tmp.daily_max_limit
	self.t_config.query_data_mapid = t_tmp.query_data_mapid
	return self
end

ShareConfig.readMap = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	if mis_uu.tableIsEmpty(t_tmp.map or {}) then
		error(self.s_workType .. ": map is empty")
	end

	local t_config = { t_map = {}}
	for _, mapConf in pairs(t_tmp.map) do
		local t_awardLimit = {}
		for _, awardItem in pairs(mapConf.award or {}) do
			t_awardLimit[awardItem.id] = {
				n_limit      = tonumber(awardItem.limit),
				b_dailyLimit = awardItem.dailyLimit and tonumber(awardItem.dailyLimit) == 1 and true or false,
			}
		end
		t_config.t_map[mapConf.mapID] = {
			s_name       = mapConf.name,
			n_startTime  = mapConf.startTime and mis_common.date_to_unix(mapConf.startTime),
			n_endTime    = mapConf.endTime   and mis_common.date_to_unix(mapConf.endTime),
			t_awardLimit = t_awardLimit
		}
	end

	mis_log.day("share_mission", self.s_workType .. ' readMap: ' .. n_labelId .. "|" .. uu.to_str(n_taskId) .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取绑定手机配置
ShareConfig.bindPhone = function(self, n_labelId)
	local t_tmp = self:ensureConfig(n_labelId)
	if mis_uu.tableIsEmpty(t_tmp.bind_phone or {}) then
		error(self.s_workType .. ": bind phone is empty")
	end

	local t_config = {
		t_bind_phone  = t_tmp.bind_phone
	}

	mis_log.day("share_mission", self.s_workType .. ' readLevel: ' .. n_labelId .. "|" .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取会员主题奖励配置
ShareConfig.vip_theme_prize = function(self, n_labelId)
	local t_tmp = self:ensureConfig(n_labelId)
	if mis_uu.tableIsEmpty(t_tmp.vip_theme or {}) then
		error(self.s_workType .. ": vip_theme is empty")
	end

	local t_config = {
		vip_theme  = t_tmp.vip_theme
	}

	mis_log.day("share_mission", self.s_workType .. ' readLevel: ' .. n_labelId .. "|" .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end

-- 读取分享码配置
ShareConfig.readMapCode = function(self, n_labelId, n_taskId)
	local t_tmp = self:ensureConfig(n_labelId, n_taskId)
	local t_config = {}
	local t_code = {}
	local t_specialCode = {}

	-- 没有商城配置
	if not mis_uu.tableNotEmpty(t_tmp.shareCode) then
		error(self.s_workType .. ": share code is empty")
	end

	-- 公共分享码
	t_code.n_verify = t_tmp.shareCode.tickOpt or 1						-- 添加好友验证勾选项，默认勾选(0 不勾选，1勾选)
	t_code.n_suffix = t_tmp.shareCode.suffix or 6						-- 分享码前缀
	t_code.n_maxExchange = t_tmp.shareCode.maxExchange or 50			-- 分享码最大兑换次数
	t_code.n_maxUserExchange = t_tmp.shareCode.maxUserExchange or 3		-- 分享码单个用户最大兑换次数
	t_code.n_expireType = t_tmp.shareCode.expireType or 2				-- 分享码过期方式：1 当天有效，2 按时间倒计时
	t_code.n_expire = t_tmp.shareCode.expireTime or 172800				-- 分享码过期时间（单位：秒）
	t_code.s_pattern = t_tmp.shareCode.pattern or "#%w"					-- 分享码正则匹配(用于快速校验，由开发填写，默认是：#%w)

	-- 大V口令特殊处理
	if t_tmp.specialCode and mis_uu.tableNotEmpty(t_tmp.specialCode) then
		for k, v in pairs(t_tmp.specialCode) do
			if v.uin and v.maxExchange then
				table.insert(t_specialCode, {n_uin=tonumber(v.uin), n_maxExchange=tonumber(v.maxExchange)})
			end
		end
	end

	t_config.t_shareCode = t_code
	t_config.t_specialCode =  t_specialCode

	mis_log.day("share_mission", self.s_workType .. ' readMapCode: ' .. n_labelId .. "|" .. mis_common.table_to_string(t_config))

	-- copy to output config
	for k, v in pairs(t_config) do
		self.t_config[k] = v
	end

	return self
end
--------------------------------------------------------------
-- 任务配置
this.handle_mission_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_mission_conf using_content-1 |" .. #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_mission_conf error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_mission_conf return empty" )
		return
	end

	local t_, t_2, t_tmp, t_tmp2
	local n_nowtime = ngx.time()

	t_tmp, t_tmp2 = {t_label = {}}, {}
	for n_id1, t_label in pairs(t_ret) do
		if type(n_id1) == 'number' and n_id1 <= 2 then
			t_ = {
				n_id = n_id1;
				n_type = t_label.type;
				n_startTime = t_label.startTime and mis_common.date_to_unix(t_label.startTime);
				n_endTime = t_label.endTime and mis_common.date_to_unix(t_label.endTime);
				n_duration = t_label.duration and t_label.duration * 3600 or nil;
				t_ABTest = t_label.ABTest;
				n_verMin = t_label.versionMin and mis_common.version_to_number(t_label.versionMin) or nil;
				b_auto = t_label.auto and t_label.auto or nil;
				t_task = {};
			}
			for n_id2, t_task in pairs(t_label.mission) do
				t_2 = {
					n_id = n_id2;
					n_labelId = n_id1;
					n_startTime = t_task.startTime and mis_common.date_to_unix(t_task.startTime);
					n_endTime = t_task.endTime and mis_common.date_to_unix(t_task.endTime);
					n_daily = t_task.daily and (type(t_task.daily) == 'string' and (mis_common.clock_to_second(t_task.daily)) or 86400) or nil;
					b_weekly = t_task.weekly and true or nil;
					n_event = t_task.event;
				}
				if t_task.bonus then
					t_2.t_bonus = {}
					for _, t_3 in ipairs(t_task.bonus) do
						table.insert(t_2.t_bonus, {id = t_3.itemId, num = t_3.num})
					end
				elseif t_task.selectBonus then
					t_2.t_selectBonus = {}
					for n_id, t_3 in pairs(t_task.selectBonus) do
						t_2.t_selectBonus[n_id] = {}
						for _, t_4 in ipairs(t_3) do
							table.insert(t_2.t_selectBonus[n_id], {id = t_4.itemId, num = t_4.num})
						end
					end
				end
				if type(t_task.target) == 'string' then
					t_2.tn_target = {}
					for s_ in t_task.target:gmatch('(%d+)') do
						table.insert(t_2.tn_target, tonumber(s_))
					end
				else
					t_2.tn_target = t_task.target
				end
				t_.t_task[n_id2] = t_2
				if not t_tmp2[t_task.event] then t_tmp2[t_task.event] = {} end
				table.insert(t_tmp2[t_task.event], t_2)
			end
			if t_label.random then
				t_2 = {
					n_daily = t_label.random.daily and (type(t_label.random.daily) == 'string' and (mis_common.clock_to_second(t_label.random.daily)) or 86400) or nil;
					n_time = t_label.random.time;
					n_refreshTime = t_label.random.refreshTime;
					b_once = t_label.random.once;
					t_pool = {t_first = {}, t_default = {}};
				}
				for s_a, s_b in t_label.random.pool.first:gmatch('(%d+)|(%d+)') do
					if tonumber(s_b) > 0 then
						table.insert(t_2.t_pool.t_first, {n_taskId = tonumber(s_a), n_ratio = tonumber(s_b)})
					end
				end
				for s_a, s_b in t_label.random.pool.default:gmatch('(%d+)|(%d+)') do
					if tonumber(s_b) > 0 then
						table.insert(t_2.t_pool.t_default, {n_taskId = tonumber(s_a), n_ratio = tonumber(s_b)})
					end
				end
				t_.t_random = t_2
			end
			t_tmp.t_label[n_id1] = t_
		end
	end
	this.t_mission.t_conf = t_tmp
	this.t_mission.t_eventConf = t_tmp2
	this.t_mission.n_status = t_ret.control == 1 and mis_config.t_workStatus.n_ENABLE or mis_config.t_workStatus.n_DISABLE
	this.t_mission.s_md5 = ngx.md5(mis_common.table_to_string(this.t_mission))

	this.t_twoback.t_conf_long  = uu.table_value_copy(t_ret[3]) or {}
	this.t_twoback.t_conf_short = uu.table_value_copy(t_ret[4]) or {}
	this.t_twoback.n_status = mis_config.t_workStatus.n_ENABLE

	this.t_nationalday.t_conf   = uu.table_value_copy(t_ret[5]) or {}
	this.t_nationalday.n_status = mis_config.t_workStatus.n_ENABLE

	this.t_growthguard.t_conf   = uu.table_value_copy(t_ret[6]) or {}
	this.t_growthguard.n_status = mis_config.t_workStatus.n_ENABLE
	
	--this.t_moon.t_conf   = uu.table_value_copy(t_ret[28]) or {}
	--this.t_moon.n_status = mis_config.t_workStatus.n_ENABLE


	this.handle_relic_imitate_conf(t_content)

	this.handle_concert_conf(t_content)
	
	this.handle_novice_task_conf(t_content)

	local n_code, t_temp, b_ok, s_desc
	n_code, t_temp =  this.handle_share_mission_conf(t_content, 10)
	if n_code == t_retCode.n_OK then
		this.t_share_mission['contest_map'] = t_temp
	end

	n_code, t_temp =  this.handle_share_mission_conf(t_content, 11)
	if n_code == t_retCode.n_OK then
		this.t_share_mission['contest_video'] = t_temp
	end

	n_code, t_temp =  this.handle_share_mission_conf(t_content, 12)
	if n_code == t_retCode.n_OK then
		this.t_share_mission['contest_social'] = t_temp
	end

	n_code, t_temp =  this.handle_share_mission_conf(t_content, 15)
	if n_code == t_retCode.n_OK then
		this.t_share_mission['flower_xiaolou'] = t_temp
	end
	
	-- 读取大唐年迎财神配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "wealth_god")
			:readControl(13)				-- 读取开关配置
			:readMission(13, 3)				-- 读取任务配置
			:readWealthGod(13, 3)			-- 读取迎财神专属配置
			:getConfig()
		this.t_share_mission['wealth_god'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取大唐年迎唐年配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "tang_year")
			:readControl(13)				-- 读取开关配置
			:readMission(13, 4)				-- 读取任务配置
			:getConfig()
		this.t_share_mission['tang_year'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取大唐年战年兽配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "year_beast")
			:readControl(13)				-- 读取开关配置
			:readMission(13, 5)				-- 读取任务配置
			:getConfig()
		this.t_share_mission['year_beast'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end
	
	-- 读取大唐年小唐人配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "tang_people")
			:readControl(13)				-- 读取开关配置
			:readMission(13, 1)				-- 读取任务配置
			:readCode(13, 1)				-- 读取分享码配置
			:getConfig()
		this.t_share_mission['tang_people'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end
	
	-- 读取大唐年上元节配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "lantern_festival")
			:readControl(13)				-- 读取开关配置
			:readMission(13, 2)				-- 读取任务配置
			:getConfig()
		t_temp.t_conf.n_maxDailyFire = tonumber(t_ret[13].taskList[2].max_daily_fire) or 0
		this.t_share_mission['lantern_festival'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取大唐年红包集市配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "red_packet")
			:readControl(13)				-- 读取开关配置
			:readStore(13)					-- 读取分享码配置
			:getConfig()
		this.t_share_mission['red_packet'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取大唐年开宝箱配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "year_roll")
			:readControl(13)				-- 读取开关配置
			:readRoll(13, 6)				-- 读取抽奖配置
			:getConfig()
		this.t_share_mission['year_roll'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取大唐年链接弹窗配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "share_activity")
			:readControl(13)				-- 读取开关配置
			:readMission(13, 7)				-- 读取任务配置
			:getConfig()
		this.t_share_mission['share_activity'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取冬雪派对配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "snow_party")
			:readControl(16)				-- 读取开关配置
			:readMission(16)				-- 读取任务配置
			:getConfig()
		this.t_share_mission['snow_party'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取迷你派对配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "mini_party")
							:readControl(17)				-- 读取开关配置
							:readMiniParty(17, 1)				-- 读取任务配置
							:getConfig()
		this.t_share_mission['mini_party'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取共筑长城配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "build_greatwall")
							:readControl(17)				-- 读取开关配置
							:readMission(17, 2)				-- 读取任务配置
							:getConfig()
		this.t_share_mission['build_greatwall'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end
	
	-- 读取组建护卫队配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "create_convoy")
							:readControl(17)				-- 读取开关配置
							:readMission(17, 3)				-- 读取任务配置
							:getConfig()
		t_temp.t_conf.n_teamCapacity = tonumber(t_ret[17].taskList[3].teamCapacity) or 0
		this.t_share_mission['create_convoy'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end
	
	-- 读取虚空入侵配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "void_invade")
							:readControl(17)				-- 读取开关配置
							:readMission(17, 4)				-- 读取任务配置
							:getConfig()
		t_temp.t_conf.n_scoreUnit = tonumber(t_ret[17].taskList[4].score_unit) or 0
		this.t_share_mission['void_invade'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end
	
	-- 读取周年庆开宝箱配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "anniversary_roll")
			:readControl(17)				-- 读取开关配置
			:readRoll(17, 5)				-- 读取抽奖配置
			:getConfig()
		this.t_share_mission['anniversary_roll'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取周年庆典商店配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, "anniversary_store")
							:readControl(17)				-- 读取开关配置
							:readStore(17)					-- 读取商店配置
							:readCurrency(17)				-- 读取代币配置
							:getConfig()
		this.t_share_mission['anniversary_store'] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取觉醒活动
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_AWAKENING_ACTIVITY)
			:readControl(20)				-- 读取开关配置
			:readLevel(20)					-- 读取等级
			:readStore(20)					-- 读取商城
			:readMap(20)					-- 读取地图
			:readRank(20)					-- 读取排行榜
			:getConfig()
		this.t_awakening_activity = t_temp

		if t_temp.n_status == mis_config.t_workStatus.n_ENABLE then
			-- 业务配置校验
			for _, t_good in pairs(t_temp.t_conf.t_store.t_goods or {}) do
				for id, t_goodItem in pairs(t_good.t_items or {}) do
					if  t_goodItem.id == mis_config.t_specialItemMap.s_SHARE
					and t_goodItem.num ~= 1 then
						error( 'store tickets num must 1: index = ' .. id)
					end
				end
			end

			-- 注册排行榜
			if  t_temp.t_conf.n_startTime <= n_nowtime
			and t_temp.t_conf.n_endTime   >  n_nowtime then
				for ID, t_opt in pairs(this.t_awakening_activity.t_conf.t_rank) do
					local rank_name = 'awakening_'..ID
					local t_rankOpt = mis_uu.table_value_copy(t_opt)
					t_rankOpt.updates  = nil	-- 统一业务层做缓存然后全量更新榜单
					t_rankOpt.end_time = t_temp.t_conf.n_endTime
					local _, err = mis_rank.register(rank_name, mis_config.t_redis.connect, t_rankOpt)
					if err then
						error('rank register fail : ' .. rank_name)
					end
				end
			end
		end
	end)
	if not b_ok then
		mis_log.day( "center_server", "awakening_activity error|" .. s_desc)
	end


	-- 读取觉醒主页
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_AWAKENING_HOMEPAGE)
			:readControl(20)				-- 读取开关配置
			:readMission(20, 1)				-- 读取任务配置
			:getConfig()
		this.t_share_mission[mis_config.t_workType.s_AWAKENING_HOMEPAGE] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "awakening_homepage error|" .. s_desc)
	end

	-- 读取觉醒秘籍配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_AWAKENING_BOOKS)
			:readControl(20)				-- 读取开关配置
			:readMission(20, 2)				-- 读取任务配置
			:readCode(20, 2)				-- 读取分享码配置
			:getConfig()
		this.t_share_mission[mis_config.t_workType.s_AWAKENING_BOOKS] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "awakening_books error|" .. s_desc)
	end

	-- 读取觉醒发布会配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_AWAKENING_MOVIE)
			:readControl(20, 3)				-- 读取开关配置
			:readMission(20, 3)				-- 读取任务配置
			:getConfig()
		this.t_share_mission[mis_config.t_workType.s_AWAKENING_MOVIE] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", "awakening_movie error|" .. s_desc)
	end

	-- 读取迷你打工人任务
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_MINI_WORKER_MISSION)
							:readControl(21)				-- 读取开关配置
							:readMission(21, 1)				-- 读取任务配置
							:getConfig()
		this.t_share_mission[mis_config.t_workType.s_MINI_WORKER_MISSION] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", mis_config.t_workType.s_MINI_WORKER_MISSION .. " error|" .. s_desc)
	end
	-- 读取迷你打工人商城
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_MINI_WORKER_STORE)
							:readControl(21)				-- 读取开关配置
							:readStore(21)
							:getConfig()
		this.t_share_mission[mis_config.t_workType.s_MINI_WORKER_STORE] = t_temp
	end)
	if not b_ok then
		mis_log.day( "center_server", mis_config.t_workType.s_MINI_WORKER_STORE .. " error|" .. s_desc)
	end

	-- 读取端午节活动任务
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_BOAT_FESTIVAL_ACTIVITY)
							:readControl(22)				-- 读取开关配置
							:readMission(22, 1)				-- 读取任务配置
							:readRank(22)					-- 读取排行榜
							:readCode(22, 1)				-- 读取分享码配置
							:readStore(22)					-- 商店配置
							:bindPhone(22)					-- 绑定手机
							:getConfig()

		this.t_share_mission[mis_config.t_workType.s_BOAT_FESTIVAL_ACTIVITY] = t_temp

		if t_temp.n_status == mis_config.t_workStatus.n_ENABLE then
			-- 注册排行榜
			if  t_temp.t_conf.n_startTime <= n_nowtime
			and t_temp.t_conf.n_endTime   >  n_nowtime then
				for ID, t_opt in pairs(t_temp.t_conf.t_rank) do
					local rank_name = 'boat_festival_'..ID
					local t_rankOpt = mis_uu.table_value_copy(t_opt)
					t_rankOpt.updates  = nil	-- 统一业务层做缓存然后全量更新榜单
					t_rankOpt.end_time = t_temp.t_conf.n_endTime
					local _, err = mis_rank.register(rank_name, mis_config.t_redis.connect, t_rankOpt)
					if err then
						error('rank register fail : ' .. rank_name)
					end
				end
			end
		end
	
	end)
	if not b_ok then
		mis_log.day( "center_server", mis_config.t_workType.s_BOAT_FESTIVAL_ACTIVITY .. " error|" .. s_desc)
	end

	-- 读取全名创造任务
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.S_ALL_CREATE)
							:readControl(23)				-- 读取开关配置
							:readMission(23, 1)				-- 读取任务配置
							:readStore(23)					-- 读取商店
							:getConfig()
		this.t_share_mission[mis_config.t_workType.S_ALL_CREATE] = t_temp
	end)

	-- 读取会员主题任务
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_VIP_THEME)
							:readControl(25)				-- 读取开关配置
							:readMission(25, 1)				-- 读取任务配置
							:vip_theme_prize(25)				       -- 会员主题奖励
							:getConfig()
		this.t_share_mission[mis_config.t_workType.s_VIP_THEME] = t_temp
	end)

	if not b_ok then
		mis_log.day( "center_server", mis_config.t_workType.s_VIP_THEME .. " error|" .. s_desc)
	end

	-- 读取斗罗大陆配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_DOULUODALU)
							:readControl(24)				-- 读取开关配置
							:readDouluodalu(24)
							:readRank(24)					-- 读取排行榜
							:readStore(24)					-- 读取商店
							:getConfig()
		this.t_share_mission[mis_config.t_workType.s_DOULUODALU] = t_temp
		if t_temp.n_status == mis_config.t_workStatus.n_ENABLE then
			-- 注册排行榜
			if  t_temp.t_conf.n_startTime <= n_nowtime
			and t_temp.t_conf.n_endTime   >  n_nowtime then
				for ID, t_opt in pairs(t_temp.t_conf.t_rank) do
					local rank_name = 'douluo_'..ID
					local t_rankOpt = mis_uu.table_value_copy(t_opt)
					t_rankOpt.updates  = nil	-- 统一业务层做缓存然后全量更新榜单
					t_rankOpt.end_time = t_temp.t_conf.n_endTime
		
					local _, err = mis_rank.register(rank_name, mis_config.t_redis.connect, t_rankOpt)
				
					if err then
						error('rank register fail : ' .. rank_name)
					end
				end
			end
		end
	end)
	if not b_ok then
		mis_log.day( "center_server", mis_config.t_workType.s_DOULUODALU .. " error|" .. s_desc)
	end

	-- 读取联机地图分享配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_MAP_SHARE)
							:readControl(26)				-- 读取开关配置
							:readMapCode(26)				-- 读取分享码配置
							:getConfig()
		this.t_share_mission[mis_config.t_workType.s_MAP_SHARE] = t_temp
	end)

	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end

	-- 读取地图口令分享配置
	b_ok, s_desc = pcall(function()
		t_temp = ShareConfig.load(t_content, mis_config.t_workType.s_MAP_CODE)
							:readControl(27)				-- 读取开关配置
							:readMapCode(27)				-- 读取分享码配置
							:getConfig()
		this.t_share_mission[mis_config.t_workType.s_MAP_CODE] = t_temp
	end)

	if not b_ok then
		mis_log.day( "center_server", "handle_share_mission error|" .. s_desc)
	end
end

--------------------------------------------------------------
-- 生日系统配置
this.handle_birthday_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_birthday_conf " .. "using_content-1" .. '|' .. #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_birthday_conf " .. "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_birthday_conf " .. "return empty" )
		return
	end

	local sn_code
	local s_desc
	local t_sysUser, t_sysConf

	t_sysUser = this.get_user(0)
	sn_code, t_sysConf = t_sysUser:get_birthday_conf()
	if sn_code ~= t_retCode.n_OK then
		return sn_code, t_sysConf
	end

	t_ret.onshow = tonumber(t_ret.onshow or 0)
	t_ret.start_time = t_ret.start_time or '2021-01-01 00:00:00'
	t_ret.end_time = t_ret.end_time or '2121-01-01 00:00:00'
	t_ret.cake = t_ret.cake or {}
	t_ret.cake.itemID = tonumber(t_ret.cake.itemID or 0)
	t_ret.cake.num = tonumber(t_ret.cake.num or 0)
	t_ret.version_min = t_ret.version_min or '0.0.0'
	t_ret.duration.stime = t_ret.duration.stime or 0
	t_ret.duration.etime = t_ret.duration.etime or 0
	t_ret.unauth_count	= t_ret.unauth_count or 15

	this.t_birthday.t_conf = t_ret
	if t_ret.onshow == 1 then
		this.t_birthday.n_status =  mis_config.t_workStatus.n_ENABLE
	else
		this.t_birthday.n_status =  mis_config.t_workStatus.n_DISABLE
	end

	sn_code, s_desc = t_sysUser:set_birthday_conf(t_ret)
	if sn_code ~= t_retCode.n_OK then
		return sn_code, s_desc
	end
end

--------------------------------------------------------------
---｛｛
-- H5活动配置（双旦活动）
this.handle_h5_doubledan_conf = function(t_content)
    local t_ret
    if t_content then
        mis_log.day("center_server", "handle_h5_conf " .. "using_content-1" .. '|' .. #t_content)
        t_ret = mis_uu.safe_loadstring(t_content, true)
    else
        mis_log.day("center_server", "handle_h5_conf " .. "error_no_content")
        return
    end
    if not mis_uu.tableNotEmpty(t_ret) then
        mis_log.day("center_server", "handle_h5_conf " .. "return empty")
        return
    end
    if t_ret==nil then
        mis_log.debug("t_ret is nil")
    end
    --mis_log.debug("*************************************")
    --mis_uu.var_dump(t_ret)
    --mis_log.debug("*************************************")
    --
    this.t_doubledan.t_conf = uu.table_value_copy(t_ret) or {}
    --mis_log.debug("--------------------------------------")
    --mis_uu.var_dump(this.t_doubledan.t_conf)
    --mis_log.debug("--------------------------------------")
    if this.t_doubledan.t_conf and this.t_doubledan.t_conf.control_all == 1 then
        this.t_doubledan.n_status = mis_config.t_workStatus.n_ENABLE
    else
        this.t_doubledan.n_status = mis_config.t_workStatus.n_DISABLE
    end
end
---｝｝

--------------------------------------------------------------
-- 转盘配置
this.handle_rotate_conf = function(t_content)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_rotate_conf", "using_content-1", #t_content )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_rotate_conf", "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret) then
		mis_log.day( "center_server", "handle_rotate_conf", "return empty" )
		return
	end

	local n_1, n_2, n_3, n_4, n_5, n_6, n_7, n_8
	local t_, t_2, t_3, t_4, t_con, t_tmp, t_first, t_default

	t_tmp = t_ret
	t_ret = {
		n_startTime = mis_common.date_to_unix(t_tmp.startTime);
		n_endTime = mis_common.date_to_unix(t_tmp.endTime);
		n_closeTime = mis_common.date_to_unix(t_tmp.closeTime);
		t_first = {t_rotateRich = {}, t_rotatePoor = {}, t_rotateRichNoCoin = {}, t_rotatePoorNoCoin = {}, t_config = {}};
		t_default = {t_rotateRich = {}, t_rotatePoor = {}, t_rotateRichNoCoin = {}, t_rotatePoorNoCoin = {}, t_config = {}};
	}
	t_first = t_ret.t_first
	for n_id, t_ in pairs(t_tmp.first.config) do
		t_4 = {b_rand = t_.rand}
		t_.rand = nil
		t_first.t_config[n_id] = t_4
		for _, t_2 in ipairs(t_) do
			if not t_2.itemId then
				t_4[#t_4+1] = {}
				for _, t_3 in ipairs(t_2) do
					t_4[#t_4][#t_4[#t_4]+1] = {id = t_3.itemId, num = t_3.num}
				end
			else
				t_4[#t_4+1] = {id = t_2.itemId, num = t_2.num}
			end
		end
	end
	n_1, n_2, n_3, n_4 = 0, 0, 0, 0
	for n_id, t_ in ipairs(t_tmp.first.rotate) do
		n_1 = n_1 + t_.ratio
		n_2 = n_2 + (t_.ratio2 or t_.ratio)
		if t_tmp.first.config[n_id] and mis_common.table_find(t_tmp.first.config[n_id], function(tn_) if string_match(mis_common.table_to_json(tn_), '10002') then return true end end) then
			n_3 = n_3 + 0
			n_4 = n_4 + 0
		else
			n_3 = n_3 + t_.ratio
			n_4 = n_4 + (t_.ratio2 or t_.ratio)
		end
	end
	n_5, n_6, n_7, n_8 = 0, 0, 0, 0
	for n_id, t_ in ipairs(t_tmp.first.rotate) do
		n_5 = n_5 + t_.ratio
		t_first.t_rotateRich[n_id] = n_5 / n_1
		n_6 = n_6 + (t_.ratio2 or t_.ratio)
		t_first.t_rotatePoor[n_id] = n_6 / n_2
		if t_tmp.first.config[n_id] and mis_common.table_find(t_tmp.first.config[n_id], function(tn_) if string_match(mis_common.table_to_json(tn_), '10002') then return true end end) then
			n_7 = n_7 + 0
			n_8 = n_8 + 0
		else
			n_7 = n_7 + t_.ratio
			n_8 = n_8 + (t_.ratio2 or t_.ratio)
		end
		t_first.t_rotateRichNoCoin[n_id] = n_7 / n_3
		t_first.t_rotatePoorNoCoin[n_id] = n_8 / n_4
	end
	t_default = t_ret.t_default
	for n_id, t_ in pairs(t_tmp.default.config) do
		t_4 = {b_rand = t_.rand}
		t_.rand = nil
		t_default.t_config[n_id] = t_4
		for _, t_2 in ipairs(t_) do
			if not t_2.itemId then
				t_4[#t_4+1] = {}
				for _, t_3 in ipairs(t_2) do
					t_4[#t_4][#t_4[#t_4]+1] = {id = t_3.itemId, num = t_3.num}
				end
			else
				t_4[#t_4+1] = {id = t_2.itemId, num = t_2.num}
			end
		end
	end
	n_1, n_2, n_3, n_4 = 0, 0, 0, 0
	for n_id, t_ in ipairs(t_tmp.default.rotate) do
		n_1 = n_1 + t_.ratio
		n_2 = n_2 + (t_.ratio2 or t_.ratio)
		if t_tmp.default.config[n_id] and mis_common.table_find(t_tmp.default.config[n_id], function(tn_) if string_match(mis_common.table_to_json(tn_), '10002') then return true end end) then
			n_3 = n_3 + 0
			n_4 = n_4 + 0
		else
			n_3 = n_3 + t_.ratio
			n_4 = n_4 + (t_.ratio2 or t_.ratio)
		end
	end
	n_5, n_6, n_7, n_8 = 0, 0, 0, 0
	for n_id, t_ in ipairs(t_tmp.default.rotate) do
		n_5 = n_5 + t_.ratio
		t_default.t_rotateRich[n_id] = n_5 / n_1
		n_6 = n_6 + (t_.ratio2 or t_.ratio)
		t_default.t_rotatePoor[n_id] = n_6 / n_2
		if t_tmp.default.config[n_id] and mis_common.table_find(t_tmp.default.config[n_id], function(tn_) if string_match(mis_common.table_to_json(tn_), '10002') then return true end end) then
			n_7 = n_7 + 0
			n_8 = n_8 + 0
		else
			n_7 = n_7 + t_.ratio
			n_8 = n_8 + (t_.ratio2 or t_.ratio)
		end
		t_default.t_rotateRichNoCoin[n_id] = n_7 / n_3
		t_default.t_rotatePoorNoCoin[n_id] = n_8 / n_4
	end
	this.t_rotate.t_conf = t_ret
	this.t_rotate.n_status = mis_config.t_workStatus.n_ENABLE
end
--------------------------------------------------------------
--- version.lua
this.load_version_config = function(content_)
	local t_ret
	if  content_ then
		mis_log.day( "center_server", "load_version_config " .. "using_content" .. '|' .. #content_ )
		t_ret = mis_uu.safe_loadstring( content_, true)
	else
		mis_log.day( "center_server", "load_version_config " .. "error_no_content" )
		return
	end

	if  mis_uu.tableNotEmpty(t_ret) then
		this.t_diversion.t_conf = t_ret.diversion or {}
		if t_ret.diversion and t_ret.diversion.onshow and t_ret.diversion.onshow == 1 then
			this.t_diversion.n_status =  mis_config.t_workStatus.n_ENABLE
		else
			this.t_diversion.n_status =  mis_config.t_workStatus.n_DISABLE
		end
	else
		mis_log.day( "center_server", "load_version_config " .. "return empty" )
	end
end

--------------------------------------------------------------
-- 公共任务配置 -- 大唐中国年
this.handle_share_mission_conf2 = function(t_content, n_labelId, n_taskId)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_share_mission_conf2|using_content-1|" .. #t_content .. "|" .. uu.to_str(n_labelId) .. "|" .. uu.to_str(n_taskId) )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_share_mission_conf2|error_no_content" .. "|" .. uu.to_str(n_labelId) .. "|" .. uu.to_str(n_taskId) )
		return t_retCode.n_SYS_ERR
	end
	if not (mis_uu.tableNotEmpty(t_ret) and mis_uu.tableNotEmpty(t_ret[n_labelId])) then
		mis_log.day( "center_server", "handle_share_mission_conf2", "return empty" .. "|" .. uu.to_str(n_labelId) .. "|" .. uu.to_str(n_taskId) )
		return t_retCode.n_SYS_ERR
	end

	local t_tmp 		= t_ret[n_labelId]
	local t_conf		= {}
	local t_mission		= {}
	local t_store 		= {}
	local t_goods 		= {}
	local t_task		= {}
	local t_roll		= {}
	local t_code		= {}
	local n_status 		= mis_config.t_workStatus.n_DISABLE

	if not (mis_uu.tableNotEmpty(t_tmp) and
			t_tmp.taskList and mis_uu.tableNotEmpty(t_tmp.taskList) and
			t_tmp.taskList[n_taskId] and mis_uu.tableNotEmpty(t_tmp.taskList[n_taskId])) then
		mis_log.day( "center_server", "handle_share_mission_conf2", "return empty 2|" .. #t_ret .. "|" .. n_labelId )
		return t_retCode.n_SYS_ERR
	end

	for k, v in pairs(t_tmp.store.goods) do
		if v.items and mis_uu.tableNotEmpty(v.items) and v.price then
			local n_k			 = tonumber(k)
			t_goods[n_k]		 = {}
			t_goods[n_k].price   = tonumber(v.price)
			t_goods[n_k].limit   = tonumber(v.limit)
			t_goods[n_k].unique  = tonumber(v.unique)
			t_goods[n_k].t_items = {}

			for k2, v2 in pairs(v.items) do
				table.insert(t_goods[n_k].t_items, {id = v2.id, num = v2.num})
			end
		end
	end

	t_store = {
		n_startTime 	= mis_common.date_to_unix(t_tmp.store.startTime or '1970-01-01');
		n_endTime 		= mis_common.date_to_unix(t_tmp.store.endTime or '2030-01-01');
		s_versionMin 	= t_tmp.store.versionMin or '0';
		t_goods 		= t_goods;
	}

	t_task = t_tmp.taskList[n_taskId]
	if t_task.mission then
		for k, v in pairs(t_task.mission) do
			local t_subTask 	 = {}
			local n_eventId 	 = tonumber(v.event)
			t_mission[n_eventId] = t_mission[n_eventId] or {}
			t_subTask.t_bonus	 = {}

			if v.daily and tonumber(v.daily) == 1 then
				t_subTask.b_daily = true
			else
				t_subTask.b_daily = false
			end
			if v.weekly and tonumber(v.weekly) == 1 then
				t_subTask.b_weekly = true
			else
				t_subTask.b_weekly = false
			end

			for k2, v2 in pairs(v.bonus) do
				t_subTask.t_bonus[tonumber(k2)] = {
					s_itemId 	= v2.itemId;
					n_num 		= tonumber(v2.num);
				}
			end
			t_subTask.n_subTaskId 	= tonumber(k)
			t_subTask.n_target 		= v.target
			t_subTask.n_gainItem 	= v.gain_item
			table.insert(t_mission[n_eventId], t_subTask)
		end
	end

	if t_tmp.auto and tonumber(t_tmp.auto) == 1 then
		t_conf.b_auto = true
	else
		t_conf.b_auto = false
	end

	-- 公共抽奖
	if t_task.shareRoll then
		t_roll.n_daily = tonumber(t_task.shareRoll.daily) or 0
		t_roll.n_freeCount = tonumber(t_task.shareRoll.freeCount) or 0
		t_roll.n_videoCount = tonumber(t_task.shareRoll.videoCount) or 0
		t_roll.n_minVideoInterval = tonumber(t_task.shareRoll.minVideoInterval) or 2

		t_roll.n_totalWeight = 0
		t_roll.t_awards = {}
		for _, v in pairs(t_task.shareRoll.awards) do
			t_roll.n_totalWeight = t_roll.n_totalWeight + (v.weight or 0)
			table.insert(t_roll.t_awards, {
				s_itemId = v.itemId, n_num = tonumber(v.num), n_weight = tonumber(v.weight)
			})
		end
		t_conf.t_shareRoll = t_roll
	end

	-- 公共分享码
	if t_task.shareCode then
		t_code.t_prefix = t_task.shareCode.prefix or {}						-- 分享码前缀
		t_code.n_init = t_task.shareCode.init or 38032637					-- 分享码初始值
		t_code.n_max = t_task.shareCode.max or 60466175						-- 分享码最大值
		t_code.n_maxExchange = t_task.shareCode.maxExchange or 2				-- 分享码最大兑换次数
		t_code.n_expireType = t_task.shareCode.expireType or 1				-- 分享码过期方式：1 当天有效，2 按时间倒计时
		t_code.n_expire = t_task.shareCode.expire or 60						-- 分享码过期时间（单位：秒）
		t_code.n_maxLength = t_task.shareCode.maxLength or 20				-- 分享码最大长度(字节数，用于快速校验，由开发填写，默认是20);
		t_code.s_pattern = t_task.shareCode.pattern or "^%W+%d[0-9a-zA-Z]+$"	-- 分享码正则匹配(用于快速校验，由开发填写，默认是：^%W+%d[0-9a-zA-Z]+$)
		t_code.s_format = t_task.shareCode.format or "uint36"				-- 分享码格式化（目前支持：uint36 36进制整数）
		
		t_conf.t_shareCode = t_code
	end

	t_conf.n_startTime 	= mis_common.date_to_unix(t_task.startTime or '1970-01-01');
	t_conf.n_endTime 	= mis_common.date_to_unix(t_task.endTime or '2030-01-01');
	if t_task.tabTime and #t_task.tabTime > 0 then
		t_conf.n_tabTime = {}
		for i=1,#t_task.tabTime do
			t_conf.n_tabTime[i] = {}
			t_conf.n_tabTime[i].n_startTime = mis_common.date_to_unix(t_task.tabTime[i].startTime or '1970-01-01');
			t_conf.n_tabTime[i].n_endTime 	= mis_common.date_to_unix(t_task.tabTime[i].endTime or '1970-01-01');
		end
	end

	if n_taskId == 3 then
		t_conf.block_max = tonumber(t_task.block_max or 500);
		t_conf.award_pool = tonumber(t_task.award_pool or 10000000);
		t_conf.mini_coin_prob = tonumber(t_task.mini_coin_prob or 15);
		t_conf.minicoin_award_pool = t_task.minicoin_award_pool
		t_conf.red_envelope_award_pool  = t_task.red_envelope_award_pool 

		t_conf.low_value_user  = t_task.low_value_user 
		t_conf.low_value_user.time = mis_common.date_to_unix(t_conf.low_value_user.time or '2022-01-01');
		t_conf.assist_man_count = tonumber(t_task.assist_man_count or 4)
	end
	t_conf.t_apiids 	= t_tmp.apiids and mis_uu.split(t_tmp.apiids, ',') or {};
	t_conf.t_noapiids 	= t_tmp.t_noapiids and mis_uu.split(t_tmp.t_noapiids, ',') or {};
	t_conf.n_version_min = mis_common.version_to_number(t_tmp.versionMin or '0.0.0');
	t_conf.n_exchange_type	= tonumber(t_task.exchange_type or 0);
	t_conf.t_mission 	= t_mission;
	t_conf.t_store		= t_store;

	if t_tmp.control and tonumber(t_tmp.control) == 1 then
		n_status = mis_config.t_workStatus.n_ENABLE
	end

	mis_log.day("share_mission", 'handle_share_mission_conf2: ' ..n_labelId .. "|" .. n_taskId .. "|" .. mis_common.table_to_string(t_conf))
	return t_retCode.n_OK, { t_conf = t_conf, n_status = n_status}
end

--------------------------------------------------------------
-- 公共任务配置
this.handle_share_mission_conf = function(t_content, n_labelId)
	local t_ret
	if  t_content then
		mis_log.day( "center_server", "handle_share_mission_conf|using_content-1|" .. #t_content .. "|" .. n_labelId )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "center_server", "handle_share_mission_conf|error_no_content" .. "|" .. n_labelId )
		return t_retCode.n_SYS_ERR
	end
	if not (mis_uu.tableNotEmpty(t_ret) and mis_uu.tableNotEmpty(t_ret[n_labelId])) then
		mis_log.day( "center_server", "handle_share_mission_conf", "return empty" .. "|" .. n_labelId )
		return t_retCode.n_SYS_ERR
	end

	local t_tmp 		= t_ret[n_labelId]
	local t_conf		= {}
	local t_mission		= {}
	local t_store 		= {}
	local t_goods 		= {}
	local t_candidate	= {}
	local n_status 		= mis_config.t_workStatus.n_DISABLE

	if not mis_uu.tableNotEmpty(t_tmp) then
		mis_log.day( "center_server", "handle_share_mission_conf", "return empty 2|" .. #t_ret .. "|" .. n_labelId )
		return
	end

	for k, v in pairs(t_tmp.store.goods) do
		if v.items and mis_uu.tableNotEmpty(v.items) and v.price then
			local n_k			 = tonumber(k)
			t_goods[n_k]		 = {}
			t_goods[n_k].price   = tonumber(v.price)
			t_goods[n_k].limit   = tonumber(v.limit)
			t_goods[n_k].unique  = tonumber(v.unique)
			t_goods[n_k].t_items = {}

			for k2, v2 in pairs(v.items) do
				table.insert(t_goods[n_k].t_items, {id = v2.id, num = v2.num})
			end
		end
	end

	for _, v in pairs(t_tmp.candidate) do
		t_candidate[v.uin] = v.initial_vote or 0
	end

	t_store = {
		n_startTime 	= mis_common.date_to_unix(t_tmp.store.startTime or '1970-01-01');
		n_endTime 		= mis_common.date_to_unix(t_tmp.store.endTime or '2030-01-01');
		s_versionMin 	= t_tmp.store.versionMin or '0';
		t_goods 		= t_goods;
	}

	for k, v in pairs(t_tmp.mission) do
		local t_subTask 	 = {}
		local n_eventId 	 = tonumber(v.event)
		t_mission[n_eventId] = t_mission[n_eventId] or {}
		t_subTask.t_bonus	 = {}

		if v.daily and tonumber(v.daily) == 1 then
			t_subTask.b_daily = true
		else
			t_subTask.b_daily = false
		end
		if v.weekly and tonumber(v.weekly) == 1 then
			t_subTask.b_weekly = true
		else
			t_subTask.b_weekly = false
		end

		for k2, v2 in pairs(v.bonus) do
			t_subTask.t_bonus[tonumber(k2)] = {
				s_itemId 	= v2.itemId;
				n_num 		= tonumber(v2.num);
			}
		end
		t_subTask.n_subTaskId 	= tonumber(k)
		t_subTask.n_target 		= v.target
		table.insert(t_mission[n_eventId], t_subTask)
	end

	if t_tmp.auto and tonumber(t_tmp.auto) == 1 then
		t_conf.b_auto = true
	else
		t_conf.b_auto = false
	end

	t_conf.n_startTime 	= mis_common.date_to_unix(t_tmp.startTime or '1970-01-01');
	t_conf.n_startEndTime 	= mis_common.date_to_unix(t_tmp.startEndTime or '1970-01-01');
	t_conf.n_endTime 	= mis_common.date_to_unix(t_tmp.endTime or '2030-01-01');
	t_conf.t_apiids 	= t_tmp.apiids and mis_uu.split(t_tmp.apiids, ',') or {};
	t_conf.t_noapiids 	= t_tmp.t_noapiids and mis_uu.split(t_tmp.t_noapiids, ',') or {};
	t_conf.n_version_min = mis_common.version_to_number(t_tmp.versionMin or '0.0.0');
	t_conf.n_exchange_type	= tonumber(t_tmp.exchange_type or 0);
	t_conf.t_mission 	= t_mission;
	t_conf.t_store		= t_store;
	t_conf.t_candidate  = t_candidate;
	t_conf.maps  		= t_tmp.maps;
	t_conf.unlock_award = t_tmp.unlock_award;
	if t_tmp.control and tonumber(t_tmp.control) == 1 then
		n_status = mis_config.t_workStatus.n_ENABLE
	end

	mis_log.day("share_mission", 'handle_share_mission_conf: ' ..n_labelId .. "|" .. mis_common.table_to_string(t_conf))
	return t_retCode.n_OK, { t_conf = t_conf, n_status = n_status}
end

--------------------------------------------------------------
--------------------------------------------------------------
-- cdkey兑奖码配置
this.handle_cdkey_config = function (t_content)
	local loaded = mis_uu.safe_loadstring(t_content)
	-- !@ 觉醒电影票
	if loaded.awakening_activity then
		if tonumber(loaded.awakening_activity.enable) == 1 and loaded.awakening_activity.tickets then
			-- 加载电影票兑换码
			this.t_awakening_tickets.n_status = mis_config.t_workStatus.n_ENABLE
			this.t_awakening_tickets.t_conf = this.t_awakening_tickets.t_conf or {}
			this.t_awakening_tickets.t_conf.total = #loaded.awakening_activity.tickets
			local _, err = mis_frashsale:register(
				mis_config.t_workType.s_AWAKENING_ACTIVITY,
				mis_config.t_redis.connect,
				loaded.awakening_activity.tickets
			)
			if err then
				error('loading awakening_activity tickets fail : ' .. err)
			end
		end
	end
end

--------------------------------------------------------------
-- 会员购买配置
this.handle_business_general_config = function (t_content)
	local t_ret     = nil
	if  t_content then
		mis_log.day( "vip_theme", "handle_business_general_config " .. "using_content-1" )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "vip_theme", "handle_business_general_config " .. "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret)  then
		mis_log.day( "vip_theme", "handle_business_general_config " .. "return empty" )
		return
	end

	this.VipCardBuy = this.VipCardBuy or {}
	if mis_uu.tableNotEmpty(t_ret.VipCardBuy)  then
		for _, cfg in next, t_ret.VipCardBuy do
			this.VipCardBuy[cfg.store_id] = cfg
		end
	end
	
	mis_log.day("vip_theme", 'handle_business_general_config: ' .. mis_uu.to_str(this.VipCardBuy))
end

--三丽鸥购买配置
this.handle_sanrio_config = function (t_content)
	local t_ret     = nil
	if t_content then
		mis_log.day( "mis_sanrio", "handle_sanrio_config " .. "using_content-1" )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "mis_sanrio", "handle_sanrio_config " .. "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret)  then
		mis_log.day( "mis_sanrio", "handle_sanrio_config " .. "return empty" )
		return
	end
	
	if not t_ret.sanrio2_cfg  then 
		mis_log.day( "mis_sanrio", "handle_sanrio_config " .. "t_ret.sanrio_activity empty" )
		return
	end

	this.t_sanrio.t_conf = t_ret.sanrio2_cfg 
	if this.t_sanrio.t_conf.share_cfg then 
		this.t_sanrio.t_conf.share_cfg.t_codePrefix = {}
		for _, v in ipairs(this.t_sanrio.t_conf.share_cfg.codePrefix) do
			table.insert(this.t_sanrio.t_conf.share_cfg.t_codePrefix, v.value)
		end	
	end
end	

--三丽鸥中秋活动配置
this.handle_moon_config = function (t_content)
	local t_ret     = nil
	if t_content then
		mis_log.day( "mis_moon", "handle_moon_config " .. "using_content-1" )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "mis_moon", "handle_moon_config " .. "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret)  then
		mis_log.day( "mis_moon", "handle_moon_config " .. "return empty" )
		return
	end

	this.t_moon.t_conf = t_ret
end	

--皮肤物品表
this.handle_item_use_skin_def_config = function (content_)
    local function onload()
        assert(content_)
        local fn =loadstring(content_)
    	this.t_item_use_skin_def_config.t_conf = fn()
    end
    xpcall(onload, function (errmsg)
        log.error( "-----------trace_back errmsg=" .. errmsg );
        log.error( debug.traceback() );
    end)
end

--活动-国庆
this.handle_currency_national_config = function (t_content)
	local t_ret     = nil
	if t_content then
		mis_log.day( "mis_currency", "handle_national_config " .. "using_content-1" )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "mis_currency", "handle_national_config " .. "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret)  then
		mis_log.day( "mis_currency", "handle_national_config " .. "return empty" )
		return
	end

	this.t_currency.t_national_conf = t_ret
end	

--活动-国庆
this.handle_currency_task_config = function (t_content)
	local t_ret     = nil
	if t_content then
		mis_log.day( "mis_currency", "handle_currency_task_config " .. "using_content-1" )
		t_ret = mis_uu.safe_loadstring( t_content, true)
	else
		mis_log.day( "mis_currency", "handle_currency_task_config " .. "error_no_content" )
		return
	end
	if not mis_uu.tableNotEmpty(t_ret)  then
		mis_log.day( "mis_currency", "handle_currency_task_config " .. "return empty" )
		return
	end

	this.t_currency.t_currency_conf = t_ret

	--[[
	local item = {}
	item.event=2001
	item.taskType=1
	item.name="开启8次星辉礼盒"
	item.target=2
	item.daily = 1
	item.bonus={}
	item.bonus.num = 10
	item.bonus.itemId = 4
	table.insert(this.t_currency.t_currency_conf.task_cfg.task_list, item)
	--]]
end	

--------------------------------------------------------------
-- 说明：load级初始化
this.init_load = function()
	math.randomseed(tostring(os_time()):reverse():sub(1, 6))

	-- init ssdb
	if mis_config.n_ssdbType == 1 then
	else
		t_m_ssdb = mis_ssdbDcClient:new('mis_', mis_config.t_ssdbDc.t_server, mis_config.t_ssdbDc.t_select)
	end

	if ngx.worker.id() == 0 then
		if mis_calcu.is_master_server() == true then
			local _, s_err = mis_timer:new():ngx_timer_every(mis_config.n_autoCleanDBInterval, auto_clean_DB)
			if s_err then
				return t_retCode.n_SYS_ERR, 'start ngx.timer.every failed, ' .. s_err
			end
		end
	end

	mis_configMgr.register_config_file_change('ab_test', 120, function(s_content)
		mis_ABTestSDK.LoadABTestConfig(s_content)
	end, 'mission')
	mis_configMgr.register_config_file_change('servers_config', 120, function(s_content)
		local t_ = mis_uu.safe_loadstring(s_content).ab_test_config
		if t_ then mis_ABTestSDK.LoadABTestSwitchConfig(t_) end
	end, 'mission')

	mis_configMgr.register_config_file_change('cdkey_config',120,this.handle_cdkey_config,'mission')
	mis_configMgr.register_config_file_change('gift_config', 120, this.handle_gift_conf, 'mission')
	mis_configMgr.register_config_file_change('back_config', 120, this.handle_back_conf, 'mission')
	mis_configMgr.register_config_file_change('ma_config', 120, this.handle_baoku_conf, 'mission')
	mis_configMgr.register_config_file_change('cooperation', 120, this.handle_coop_conf, 'mission')
	mis_configMgr.register_config_file_change('mission', 120, this.handle_mission_conf, 'mission')
	mis_configMgr.register_config_file_change('birthday', 120, this.handle_birthday_conf, 'mission')
	mis_configMgr.register_config_file_change('rotate_config', 120, this.handle_rotate_conf, 'mission')
	mis_configMgr.register_config_file_change('version', 120, this.load_version_config, 'mission')
	mis_configMgr.register_config_file_change('doubledan',120,this.handle_h5_doubledan_conf,'mission')
	mis_configMgr.register_config_file_change('business_general_config', 120, this.handle_business_general_config, 'mission')
	mis_configMgr.register_config_file_change('Act_36',120,this.handle_sanrio_config,'mission')
	mis_configMgr.register_config_file_change('Act_38',120,this.handle_moon_config,'mission')
	mis_configMgr.register_config_file_change('ItemUseSkinDef',120, this.handle_item_use_skin_def_config, 'mission')

	mis_configMgr.register_config_file_change('Act_41',120, this.handle_currency_national_config, 'mission')
	mis_configMgr.register_config_file_change('Act_42',120, this.handle_currency_task_config, 'mission')

	local _, s_err = mis_timer:new():ngx_timer_at(3, year_beast_event_loop, true)
	if s_err then
		return t_retCode.n_SYS_ERR, 'start ngx.timer.every failed, ' .. s_err
	else
		mis_log.day("year_beast", "start ngx.timer.every | " .. ngx.worker.id())
	end

	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：request级初始化
this.init_request = function()
	ngx.ctx.t_users = {}

	-- 放在这里刷新配置的目的在于，当通过后台触发cmd刷新配置的时候，
	-- 只会在一个worker生效，其他的worker也需要同步
	local n_code, s_desc = this.load_config(true)
	if n_code ~= t_retCode.n_OK then
		return n_code, s_desc
	end

	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：析构
this.finish_request = function()
	if t_m_ssdb then
		t_m_ssdb:final()
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：参数存在性检查
-- 返回：n		状态码
--		s 		描述
this.check_fix_params = function()
	local t_params = ngx.ctx.t_params
	local t_fixParams
	if t_params.act then
		t_fixParams = mis_config.t_acts.t_fixParams
	elseif t_params.cmd then
		t_fixParams = mis_config.t_cmds.t_fixParams
	end
	local n_code, s_desc = check_params_base(t_fixParams, t_params)
	if n_code ~= t_retCode.n_OK then
		return n_code, s_desc
	end
	return n_code, s_desc
end

--------------------------------------------------------------
-- 说明：鉴权
-- 返回：n			状态码
--		s 			描述
this.check_auth_by_ver = function()
	if auth_check.check_md5_by_version() then
		return t_retCode.n_OK
	end
	return t_retCode.n_AUTH_ERR
end

--------------------------------------------------------------
-- 说明：鉴权
-- 返回：n			状态码
--		s 			描述
this.check_auth = function()
	local t_params = ngx.ctx.t_params
	local s_oper = t_params.act or t_params.cmd
	local s_auth = t_params.md5 or t_params.auth
	local s_genMd5 = mis_calcu.gen_md5_1(t_params.uin, t_params.time, t_params.s2t, t_params.act)
	if s_auth ~= s_genMd5 then
		local s_desc = 'md5 checking failed, oper=' .. s_oper
		if mis_config.n_debug == 1 or (t_params.test or not t_params.log) then
			mis_log.warning(s_desc .. ', uin=' .. t_params.uin .. ', require ' .. s_genMd5)
		end
		if mis_config.n_debug ~= 1 or not t_params.test then
			return t_retCode.n_AUTH_ERR, s_desc
		end
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：参数存在性检查
-- 参数：t_conf		配置
-- 返回：n			状态码
--		s 			描述
this.check_params = function(t_conf)
	if t_conf.t_params and t_conf.t_params.t_require then
		local b_status, n_code, s_desc = pcall(check_params_base, t_conf.t_params.t_require, ngx.ctx.t_params)
		if not b_status then
			mis_log.error('call check_params_base func error, ' .. s_desc .. ', data=' .. s_desc)
			return t_retCode.n_PARAM_ERR, s_desc
		end
		return n_code, s_desc
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：类型纠正
-- 参数：t_conf		配置
-- 返回：n			状态码
--		s 			描述
this.type_correct = function(t_conf)
	local t_params = ngx.ctx.t_params
	if t_params.act then
		type_correct_base(mis_config.t_acts.t_fixParamsToNumber, t_params)
	elseif t_params.cmd then
		type_correct_base(mis_config.t_cmds.t_fixParamsToNumber, t_params)
	end
	if t_conf.t_toNumber then
		type_correct_base(t_conf.t_toNumber, t_params)
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：长度限定
-- 参数：t_conf		配置
-- 返回：n			状态码
--		s 			描述
this.length_limit = function(t_conf)
	if t_conf.t_lenLimit then
		length_limit_base(t_conf.t_lenLimit, ngx.ctx.t_params)
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：设置全局变量
-- 参数：t_conf	配置
this.set_global_vars = function(t_conf)
	ngx.ctx.n_logLevel = t_conf.n_logLevel
end

--------------------------------------------------------------
-- 说明：加载配置
-- 参数：b_init		是否初始化
-- 返回：n			状态码
--		s	 		描述
this.load_config = function(b_init)

	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：获取服务器当前时间
this.get_server_time =  function()
	local n_stime
	local t_cache = ngx.shared.misCache
	local t_params = ngx.ctx.t_params
	local s_mission_type = t_params.mission_type or ''

	if t_cache then n_stime = t_cache:get(s_mission_type .. '_time') end
	if n_stime and n_stime ~= 0 then

	else
		n_stime = ngx.time()
	end

	return n_stime
end

--------------------------------------------------------------
-- 说明：获得玩家对象
-- 参数：n_uin			迷你号(默认是请求携带的uin)
-- 返回 t 				玩家对象
this.get_user = function(n_uin)
	if not n_uin then n_uin = ngx.ctx.t_params.uin end
	if n_uin >= 0 and n_uin < 10 then
		if not t_m_sysUser[n_uin] then t_m_sysUser[n_uin] = mis_user.new(n_uin, t_m_ssdb) end
		return t_m_sysUser[n_uin]
	else
		if not ngx.ctx.t_users[n_uin] then ngx.ctx.t_users[n_uin] = mis_user.new(n_uin, t_m_ssdb) end
		return ngx.ctx.t_users[n_uin]
	end
end

--------------------------------------------------------------
-- 说明：添加物品
-- 参数：n_uin 				迷你号
--		t_items				道具列表{{id=0,num=0},...}
--		s_workType			业务类型
--		s_reason			描述
-- 返回：n					状态码
--		s 					描述
--		s 					发送失败的道具表
this.add_items = function(n_uin, t_items, s_workType, s_reason)
	local t_normal, t_special = {}, {}
	for _, t_ in pairs(t_items) do
		if mis_config.t_specialItemMap[t_.id] then
			t_special[t_.id] = t_special[t_.id] and t_special[t_.id] + t_.num or t_.num
		else
			t_normal[#t_normal+1] = t_
		end
	end
	if next(t_special) then
		local t_user = this.get_user(n_uin)
		local n_code, t_spData = t_user:get_specialItem_data()
		if n_code ~= t_retCode.n_OK then
			return n_code, t_spData
		end
		for s_id, n_num in pairs(t_special) do
			t_spData[s_id] = t_spData[s_id] and t_spData[s_id] + n_num or n_num
		end
		local n_code, s_desc = t_user:set_specialItem_data(t_spData)
		if n_code ~= t_retCode.n_OK then
			return n_code, s_desc
		end
	end
	if #t_normal > 0 then
		return mis_bridge.add_items(n_uin, t_normal, s_workType, s_reason)
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：请求有效性校验
-- 返回 bool 			是否有效
this.check_request_valid = function()
	local t_params 	= ngx.ctx.t_params
	local n_uin  	= t_params.uin
	local n_time 	= t_params.time
	local s_act  	= t_params.act

	if mis_config.n_debug == 1 and t_params.test and t_params.test == '1' then
		return t_retCode.n_OK
	end
	if  s_act and mis_config.t_read_no_auth_acts[s_act] then
		return t_retCode.n_OK
	end

	if s_act and t_timeCache then
		local s_param	= table.tostring(ngx.ctx.m_params)
		local s_key     = ngx.md5(s_param)
		local n_exist 	= t_timeCache:get(s_key)

		if n_exist then
			mis_log.day('request_fail', 'request error|' .. n_uin .. '|' .. s_param)
			return t_retCode.n_OPER_ERR, 'request invalid'
		end

		local b_success, s_err = t_timeCache:set(s_key , 1, 7*86400) ---保存7天
		if not b_success then
			return t_retCode.n_OK, 'set ngx.shared.t_timeCache failed, ' .. s_err
		end
	end
	return t_retCode.n_OK
end

--------------------------------------------------------------
-- 说明：当前时间加上配置的偏移（只会在debug环境下读取偏移配置）
-- 返回 number			加上了配置偏移的时间
this.offset_now = function()
	if mis_config.n_debug ~= 1 then
		return uu.now()
	end
	local t_conf = this.t_growthguard.t_conf
	if t_conf == nil then
		log.day_list("growthguard","offset_now","conf nil",ngx.ctx.t_params.uin)
		return uu.now()
	end
	-- return uu.now() + (t_conf.test_offset_time or 0)
	if t_conf.test_offset_time and t_conf.test_offset_time ~= "" then
		return mis_common.date_to_unix(t_conf.test_offset_time)
	else
		return uu.now()
	end
end

--------------------------------------------------------------
-- 说明：周末好礼后台配置时间
-- 返回 number
this.weekend_gift_now = function()
	-- if mis_config.n_debug ~= 1 then
	-- 	return uu.now()
	-- end
	local t_conf = this.t_weekend_gift.t_conf
	if t_conf == nil then
		log.day_list("weekend_gift","offset_now","conf nil",ngx.ctx.t_params.uin)
		return uu.now()
	end
	if t_conf.n_test_offset_time then
		return t_conf.n_test_offset_time
	else
		return uu.now()
	end
end

--------------------------------------------------------------
-- 说明：当前时间加上配置的偏移（只会在debug环境下读取偏移配置）
-- 返回 number			加上了配置偏移的时间
this.test_offset_now = function(config)
	if mis_config.n_debug ~= 1 then
		return uu.now()
	end
	local t_conf = config.t_conf
	if t_conf == nil then
		log.day_list("test_offset_now","conf nil",ngx.ctx.t_params.uin)
		return uu.now()
	end
	if t_conf.n_test_offset_time then
		return t_conf.n_test_offset_time
	else
		return uu.now()
	end
end

--------------------------------------------------------------
-- 说明：当前时间加上配置的偏移（注意，正式环境也会生效！）
-- 返回 number			加上了配置偏移的时间
this.offset_now_v2 = function(config)
	local t_conf = config.t_conf
	if t_conf == nil then
		log.day_list("test_offset_now","conf nil",ngx.ctx.t_params.uin)
		return uu.now()
	end
	if t_conf.n_test_offset_time then
		return t_conf.n_test_offset_time
	else
		return uu.now()
	end
end

local version_min_func = function(ver, limit_ver)
    if ver == nil or limit_ver == nil then
        return false
    end

    local ver_ = uu.ver2i(ver)
    local tar_ = uu.ver2i(limit_ver)
    if ver_ and tar_  and  ver_ >= tar_  then
        return true
    end
    return false
end

--判断当前用户版本号是否能走新回流
this.check_user_ver_to_new = function()
	return version_min_func(ngx.ctx.t_params.ver, '1.5.0')
end

-- 说明：判断是否属于哪个时间段
this.wealth_god_check_appointment_date = function()
	local t_taskConf = this.t_share_mission['wealth_god'].t_conf
	local now_time = uu.now()

	if t_taskConf and t_taskConf.n_tabTime then 

		if now_time >= t_taskConf.n_tabTime[1].n_startTime and 
		now_time <= t_taskConf.n_tabTime[1].n_endTime then
			return 1 --预约阶段
		end
		 
		if now_time >= t_taskConf.n_tabTime[2].n_startTime and 
		now_time <= t_taskConf.n_tabTime[2].n_endTime then
			return 2 --财神降临阶段
		end
			
		if now_time >= t_taskConf.n_tabTime[3].n_startTime and 
		now_time <= t_taskConf.n_tabTime[3].n_endTime then
			return 3 --瓜分奖池阶段
		end

	end

	return 0
end

--获取奖池数
--返回真实的奖池数
this.wealth_god_get_award_pool = function(read_only)
	local t_sysUser = this.get_user(0)
	local code, user_data = t_sysUser:get_wealth_god_data(read_only)
	if code ~= t_retCode.n_OK then
		return code,user_data
	end

	local t_taskConf = uu.table_value_copy(this.t_share_mission['wealth_god'].t_conf)

	local flag = 1
	if mis_config.n_debug == 0 then
		flag = #mis_config.t_ssdbDc.t_select
	end

	if user_data.pool_num == nil then
		user_data.pool_num = math.floor(t_taskConf.award_pool / flag)  or 0
		user_data.minicoin_award_pool = t_taskConf.minicoin_award_pool or {}

		for k,v in pairs(user_data.minicoin_award_pool) do
			user_data.minicoin_award_pool[k].count =math_floor( (tonumber(user_data.minicoin_award_pool[k].count) or 0 )/ flag)
			user_data.minicoin_award_pool[k].money = tonumber(user_data.minicoin_award_pool[k].money) or 0
		end
	end

	return t_retCode.n_OK,user_data

end

this.wealth_god_check_award_pool = function(temp)
	
	local flag_k = {}
	for k,v in pairs(temp) do
		if v.count > 0 then
			table_insert(flag_k,k)
		end
	end

	if #flag_k > 0 then
		local t = flag_k[math_random(1,#flag_k)]

		return t_retCode.n_OK,temp[t].money, temp[t].count
	end

	return -1
end

--设置奖池数
this.wealth_god_set_award_pool = function(data)
	local t_sysUser = this.get_user(0)
	local code, user_data = t_sysUser:set_wealth_god_data(data)
	return code, user_data

end

--专门给用户专用的转换
this.wealth_god_get_award_pool_is_user = function(num)
	if mis_config.n_debug == 1 then
		return num
	end

	return num * #mis_config.t_ssdbDc.t_select
end


--专门给用户的假奖池数据
this.wealth_god_get_pool_false = function()
	local t_taskConf = this.t_share_mission['wealth_god'].t_conf
	local now_time = uu.now()
	if t_taskConf.time_pool_list then
		for i=1,#t_taskConf.time_pool_list do
			if t_taskConf.time_pool_list[i].startTime and t_taskConf.time_pool_list[i].endTime then
				if now_time >= t_taskConf.time_pool_list[i].startTime and 
				now_time <= t_taskConf.time_pool_list[i].endTime then
					return  t_taskConf.time_pool_list[i].show_pool_num or 0
					
				end

			end

		end

		return t_taskConf.time_pool_list[#t_taskConf.time_pool_list].show_pool_num or 0

	end

	return 0

end

return this
